|
Post by Pjot on Apr 1, 2016 21:27:10 GMT 1
All, Playing OGG files and WAV files work now with OpenAL, but usually, these type of files are pretty large. So, for small systems it would be nice to play small music files, like MIDI. The problem with MIDI is that a soundfont must be present, and these soundfonts can be very large too. This example MIDI player is based on libfluid and contains a small soundfont by itself. Regards Peter
|
|
|
Post by Pjot on Apr 4, 2016 20:07:23 GMT 1
All, Next to the OGG and WAV plugin for OpenAL, we now also have a MIDI plugin available, using the same API. Installing libWildMidi is required (this in Synaptic). The demonstration program is similar as used for OGG and WAV: INCLUDE openal.bac INCLUDE openal-plugin-mid.bac
OPENAL_INIT
song = MID_OPEN("prelude_and_fugue_bwv-901_(c)sankey.mid")
MID_SHOW_INFO
MID_PLAY(song)
REPEAT SLEEP 50 MID_UPDATE(song) UNTIL NOT(MID_BUSY(song))
MID_CLOSE(song)
OPENAL_FREE
Regards Peter
|
|
|
Post by vovchik on Apr 6, 2016 11:10:12 GMT 1
Dear Peter, Thanks for this. I have searched the internet and found a 1MB full GM (127 sounds plus percussion) soundfont based on the Yamaha DX7 synth. It is very hard to find a 1MB soundfont that supports full GM and still sounds OK (the AWE32 IMB SF2 dump, for example, sounds much worse). I modded your fluid (square wave data) with a c header containing the Yamaha DX7 data, which gives us a full GM and self-contained midi player that weighs in at about 1 MB. Not too bad. To create the header, unpack the dx7.sf2 archive and run: xxd -i dx7.sf2 > dx7_sf2.h Then compile fluid-dx7.bac. With kind regards, vovchik Attachments:fluid-dx7.bac.tar.gz (1.2 KB)
|
|
|
Post by Pjot on Apr 6, 2016 19:09:47 GMT 1
Thanks vovchik, Nice trick, the 'xxd' command was unknown to me, learned something new For the sound font, I also did find a generic license free soundfont called "synthgms.sf2" of 1Mb size, but the DX7 sounds better. Actually, I kind of rediscovered the MIDI format, it is an old format but very versatile, and seems to work nicely, especially for small applications. Regards Peter
|
|
|
Post by Pjot on Apr 7, 2016 21:00:49 GMT 1
All, So lastly, we have another OpenAL plugin to play midi files, however, this one is based on libfluidsynth, and it allows to specify your soundfont file. Demo program: INCLUDE openal.bac INCLUDE openal-plugin-syn.bac
OPENAL_INIT
song = SYN_OPEN("midi/prelude_and_fugue_bwv-901_(c)sankey.mid", "soundfont/dx7.sf2")
SYN_SHOW_INFO
SYN_PLAY(song)
REPEAT SLEEP 50 SYN_UPDATE(song) : ' Use in a callback UNTIL NOT(SYN_BUSY(song))
SYN_CLOSE(song)
OPENAL_FREE
PRINT "End of song."
For BaCon, the possibilities of sound always have been a little bit in the shadow. But that situation has ended now with the OpenAL interface, and the plugins. Complete list of all the files: Regards Peter
|
|
|
Post by Pjot on May 11, 2016 21:21:17 GMT 1
All, It's been busy lately, but I was able to add an MP3 plugin also, based on libmpg123. Demo program: INCLUDE openal.bac INCLUDE openal-plugin-mp3.bac
OPENAL_INIT
song = MP3_OPEN("MySong.mp3")
MP3_SHOW_INFO
MP3_PLAY(song)
REPEAT SLEEP 50 MP3_UPDATE(song) UNTIL NOT(MP3_BUSY(song))
MP3_CLOSE(song)
MP3_FREE
OPENAL_FREE
PRINT "End of song."
New overview with all sound formats: Regards Peter
|
|
|
Post by vovchik on May 11, 2016 21:37:36 GMT 1
Dear Peter, Thanks. A very nice addition and works perfectly. We can now mod the canvas midi player to play mp3s. With kind regards, vovchik
|
|
|
Post by vovchik on May 12, 2016 16:59:59 GMT 1
Dear Peter, I did what I suggested - and we now have a skinned mini player. mp3 player. Hope it works for you. With kind regards, vovchik
|
|
|
Post by Pjot on Sept 11, 2017 21:53:34 GMT 1
All, The other day I stumbled into more Single File Libraries. One of them pointed to the dr_libs, one of which contained a fully working FLAC decoder. The FLAC decoding was still on my wish list, and I was able to create a FLAC player similar to the players in previous formats. INCLUDE openal.bac INCLUDE openal-plugin-flac.bac
OPENAL_INIT
song = FLAC_OPEN("Rubinstein-Peterhof.flac")
FLAC_PLAY(song)
REPEAT SLEEP 10 FLAC_UPDATE(song) UNTIL NOT(FLAC_BUSY(song))
FLAC_CLOSE(song)
FLAC_FREE
OPENAL_FREE
Complete overview with all working sound formats: Regards Peter
|
|
|
Post by Pjot on Sept 12, 2017 18:51:04 GMT 1
Regarding the latest FLAC plugin, I discovered that some of my FLAC files do not seem to be working. It turns out that many creators of FLAC encoded files tend to add id3v2 tags. As can be observed from the xiph.org website, who are the maintainers of the FLAC reference implementation, using id3v2 tags in FLAC is not compliant with the official FLAC specification. FLAC files do support metadata tagging, but these should be added in the format of "FLAC tags" and "Vorbis comments". Though some music players are able to bypass the idv3 tags in FLAC files, the implementation from dr_libs cannot handle idv3 tags in FLAC files. So if your FLAC file cannot be played, first remove the idv3 tag: Then it can be played properly with the above OpenAL extension. When the idv3 data should be present in the file, simply add this data with the 'metaflac' utility, which uses FLAC compliant tagging. Peter EDIT: interestingly, after I converted the erroneous FLAC files so they use real Vorbis tags, all of a sudden my regular FLAC player on my Android tablet could play the files also. This never worked before and I always wondered why. So mystery solved. I made a quick script to perform the conversion from id3v2 tags to FLAC meta tags: #!/usr/bin/env bash
id3v2 --list "${1}" | awk 'BEGIN {FS=": "} /TIT2/ {print "TITLE="$2} /TPE1/ {print "ARTIST="$2} /TALB/ {print "ALBUM="$2} /TRCK/ {print "TRACKNUMBER="$2} /TYER/ {print "DATE="$2}' > /tmp/meta.info
id3v2 --delete-all "${1}"
metaflac --import-tags-from=/tmp/meta.info "${1}"
rm /tmp/meta.info
This demonstration script by no means is universal. It assumes the presence of id3v2 tags, and the tag content with a space right after the colon. But it should help to make the conversion. EDIT 2: improved the plugin so it also has an INFO function and gracefully releases memory on exit.
|
|
|
Post by Pjot on Sept 20, 2017 20:36:47 GMT 1
All, In case of XPM and SVG, it is possible to embed the drawing as plain text in the BASIC code. I wondered if such a thing is possible too for music. Long time ago, I created the PC Speaker program to play notes over the hardware speaker. This requires the proper hardware in your computer. But recent machines do not contain speakers anymore, and neither do laptops. So I wondered if there is a standard to render music using plain ASCII text definitions, similar to XPM/SVG for graphics. I did find the Lilypond project, a very active and well developed tool for converting ASCII definitions into real music scores. It also has the ability to create MIDI files. However, it does not contain an API which BaCon can use. There's also the ABC Music Project, which has longer history, and does the same thing more or less, and also provides a command line tool to convert ASCII to MIDI music. But again, no API for MIDI rendering during runtime. I decided to study the MIDI format myself and to implement the old-school Music Macro Language, just to start somewhere. The below program is the result. It needs the OpenAL and the updated MIDI plugin include files. BR Peter PS like vovchik mentioned before, it seems code is not aligned anymore by the forum... I have attached a file instead. Attachments:play.bac.gz (2.26 KB)
|
|
|
Post by vovchik on Sept 20, 2017 21:22:38 GMT 1
Dear Peter, Thanks. Just a reminder to people downloading that you first have to install wildmidi and freepats. I did something like that macro music language in some old DSP experiments where I generated a waveform at a particlular frequency, gave it a duration and then assigned it to a token (a macro language of sorts), attempting to create a kind of old BASIC PLAY statement without external dependencies. I may have called it bleep. It is somewhere on the forum, but Peter's implementation is more serious and reliable - and you can change voices/timbre. With kind regards, vovchik UPDATED: Found several versions of that bleep prog on my disk. Here is one of them (attached), but without the note/frequency mapping. Attachments:bleepy-src.tar.gz (5.41 KB)
|
|
|
Post by mackron on Sept 22, 2017 22:13:20 GMT 1
Hi All!
I'm the developer of dr_flac and I just thought I would let you know that I think I've fixed that issue where FLAC files couldn't be loaded due to those ID3 tags (how annoying!). Note, however, that I've only been able to do limited testing due to not having many sample files so there might be a few little issues. Just fire me an email if you find any bugs and I'll get it fixed!
Dave R
|
|
|
Post by vovchik on Sept 23, 2017 11:49:02 GMT 1
Dear Peter, I ran across this today (following mackron's dr_flac): TinySoundFontand think it might be a useful for a little sound extension/plugin. The nice thing is that everything is in one header - including the synthesizer. What is missing is the actual sound font, but we have a few of those lying around, some of which are complete GM implementations. While they will not be great for music, they could provide nice effects for games. I have attached one such Sf2 (gu11). In theory, it could be loaded as a header, along with TinySoundFount, and compiled in, so, in the absence of a user-provided sf2, this could serve as a default. We could then play midi and use the sounds in games. With kind regards, Vovchik PS. I have also included a VERY TINY soundfont (4k) that could be used for effects. To see the instruments in these sound fonts you can run lssf (attached). Attachments:midi.tar.gz (41.17 KB)
|
|
|
Post by Pjot on Sept 23, 2017 14:55:45 GMT 1
Hi Dave, Thanks for your excellent work on the FLAC decoder. Your latest improvements regarding the IDv3 tag work on my old erroneous FLAC files (I had made a backup of them just in case): What you see here is that the compilation with your new code works, and the test file actually is a ID3 tagged FLAC file, which now plays without any problems! Again, excellent job! I have mentioned your library more explicitly on the Basic Converter website. Best regards Peter
|
|