Skip to content

Commit

Permalink
MIDI support added
Browse files Browse the repository at this point in the history
  • Loading branch information
tai-prg3 committed Oct 16, 2018
1 parent a11c664 commit 8859ab9
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
/build/CMakeCache.txt
/build/Makefile
/build/cmake_install.cmake
*.txt.user
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,14 @@ endif (UNIX)
target_link_libraries(${PROJECT_NAME}
physfs
openal
fluidsynth
FLAC
sndfile
modplug
mpg123
ogg
vorbis
vorbisfile
vorbisenc
${ALURE_LIB}
)
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,42 @@ PhysicsFS is a library to provide abstract access to various archives. The progr
Link : <https://icculus.org/physfs/>

### Small info
Supported formats|
------------- |
WAV |
OGG |
FLAC|
MP3 |
XM, MPTM, IT, S3M |
MIDI |

> You can use another SoundFont to change the MIDI sound.
> To do this, replace the file sound_font.fs2 (there are several versions in the "build" folder).
dependencies |
------------- |
libalure |
libphysfs |
libopenal |
libfluidsynth |
libFLAC |
libsndfile |
libmodplug |
libmpg123 |
libogg |
libvorbis |
libvorbisfile |
libvorbisenc |

I used MSYS2 with mingw-w64 7.3 and cmake for create libraries in Windows.

For Ubuntu/Debian Linux:

`$ sudo apt install libalure1 libalure-dev libphysfs1 libphysfs-dev libopenal1 libopenal-dev`

`$ git clone https://github.com/vuvk/audio_system`

`$ cd audio_system/build`

`$ cmake ..`

`$ make`

`$ ./audio_system music.it`
```sh
$ sudo apt install libalure1 libalure-dev libphysfs1 libphysfs-dev libopenal1 libopenal-dev libfluidsynth1 libsndfile1 libmodplug1 libmpg123-0 libogg0 libvorbis0a libvorbisfile3 libvorbisenc2 libflac8
$ git clone https://github.com/vuvk/audio_system
$ cd audio_system/build
$ cmake ..
$ make
$ ./audio_system music.mid
```
12 changes: 12 additions & 0 deletions build/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SoundFonts used from:

sound_font_nes.sf2 = 8BitSF.sf2
8BitSF (Formerly The NES Soundfont). THE EIGHTH BIT (https://www.youtube.com/channel/UC3BDp-ftswrCsglxkOk9pVw).

sound_font.fs2 = TimGM6mb.sf2
License: GNU General Public License, version 2
Courtesy of Tim Brechbill (http://timbrechbill.com)

sound_font_piano.sf2 = ElPiano1.sf2
Unlicense? Free
NTONYX (http://ntonyx.com/sf_f.htm)
Binary file modified build/pack.zip
Binary file not shown.
Binary file added build/sound_font.sf2
Binary file not shown.
Binary file added build/sound_font_nes.sf2
Binary file not shown.
Binary file added build/sound_font_piano.sf2
Binary file not shown.
3 changes: 3 additions & 0 deletions build/test_mid.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
audio_system music.mid
pause
1 change: 1 addition & 0 deletions include/audio_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define STREAM_BUFFER_SIZE 65535 // size of chunk in bytes
#define BUFFERS_NUM 16 // count of chunks
//#define STREAM_LENGTH_MS 250000 // size of chunk in msec
#define SOUND_FONT_NAME "sound_font.sf2" // name of soundfont (*.sf2) for playing MIDI

class AudioSource
{
Expand Down
12 changes: 12 additions & 0 deletions src/audio_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ void AudioSource::setBuffer(AudioBuffer* buffer)
if (buffer->isStreamed())
{
m_stream = alureCreateStreamFromFile(buffer->getFileName().c_str(), STREAM_BUFFER_SIZE, BUFFERS_NUM, m_streamBuffer);
if (!m_stream)
{
std::cout << "Could not create a stream!" << std::endl;
std::cout << "Error: " << alureGetErrorString() << std::endl;
}

// patchset for playing midi
if (!alureSetStreamPatchset(m_stream, SOUND_FONT_NAME))
{
std::cout << "Could not load sound font '" << SOUND_FONT_NAME << "'!" << std::endl;
std::cout << "Error: " << alureGetErrorString() << std::endl;
}
}
else
{
Expand Down

0 comments on commit 8859ab9

Please sign in to comment.