A Polyphonic MUSICBOX on PIC 18F57Q84 using a sound sample as audio source.
Exploring GCBasic programming , I decided to try and make a musicbox. It resulted in a polyphonic one that can play up to 8 independent voices simultaneously.
I was asked to make a demo video and figured that 3min of a PIC chip just laying on my desk was kind boring to look at, so I added a LED-bar that shows when the voices are sounding.
The 8-bit SOUND SAMPLE is stored in program memory and uploaded to RAM on start, which is then slightly faster than reading bytes with ProgramRead. The sample is played back using a Timer0 interrupt acting sample clock at 32000 times per second, running 8 voices, so sound can be made of bytes flowing though the 8-bit DAC, read at up to 256kB/s.
In this example all voices are read from one single sound sample, which is stepped through at individual speeds (pattern of skip and repeat in the sample array) to produce the different pitches.
It would be easy to use different samples for each voice, combining percussion with different sounding instruments etc, but in this experient I decided to go for one sample making it sound kind of organ like.
The MUSIC SCORE is stored in word format and read directly using ProgramRead, stepped along by a second Timer. This conducts the voices, sets their pitches and starts them off at the right time ("Note On"). To simplify things I skipped "Note Off", so when a voice is started it just stops at its own at the end of the sample. Only when notes overlap in a voice is it stopped and restarted with the new pitch before it is finished. It does this work in the spare time inbeween interrupts.
A Polyphonic MUSICBOX on PIC 18F57Q84 using a sound sample as audio source.
Exploring GCBasic programming , I decided to try and make a musicbox. It resulted in a polyphonic one that can play up to 8 independent voices simultaneously.
I was asked to make a demo video and figured that 3min of a PIC chip just laying on my desk was kind boring to look at, so I added a LED-bar that shows when the voices are sounding.
Here is a demo video:
-Maple Leaf Rag by Scott Joplin (Public Domain).
https://lineaudio.se/div/Musicbox%20Maple%20Leaf%20Rag.mp4
(Most of the distortion is actually added by the camera)
The 8-bit SOUND SAMPLE is stored in program memory and uploaded to RAM on start, which is then slightly faster than reading bytes with ProgramRead. The sample is played back using a Timer0 interrupt acting sample clock at 32000 times per second, running 8 voices, so sound can be made of bytes flowing though the 8-bit DAC, read at up to 256kB/s.
In this example all voices are read from one single sound sample, which is stepped through at individual speeds (pattern of skip and repeat in the sample array) to produce the different pitches.
It would be easy to use different samples for each voice, combining percussion with different sounding instruments etc, but in this experient I decided to go for one sample making it sound kind of organ like.
The MUSIC SCORE is stored in word format and read directly using ProgramRead, stepped along by a second Timer. This conducts the voices, sets their pitches and starts them off at the right time ("Note On"). To simplify things I skipped "Note Off", so when a voice is started it just stops at its own at the end of the sample. Only when notes overlap in a voice is it stopped and restarted with the new pitch before it is finished. It does this work in the spare time inbeween interrupts.
Last edit: Roger Jönsson 4 days ago
Genius code!
May I make a YouTube video on this ?
Thank you! -Sure! Go ahead!
Lifted, edit, posted.
See https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/Music