Music Box / Wavetable Synthesizer / DDS

A place to document your own projects.

Re: Music Box / Wavetable Synthesizer / DDS

Postby Markus Gritsch » Tue Apr 17, 2012 5:23 am

Yes, you are right. I also thought about this, and the current implementation does not accout for this, i.e. triggering a new note of the same pitch will get another envelope on a new oscillator running.
User avatar
Markus Gritsch
Sr. Member
Sr. Member
 
Posts: 298
Joined: Tue Feb 09, 2010 6:54 am

Re: Music Box / Wavetable Synthesizer / DDS

Postby rsdio » Tue Apr 17, 2012 5:26 am

Now that I listen again to your original build, the sustain doesn't seem wrong any more. Maybe that's because this time I listened to the real thing in your link, but last time I listened to some very different acoustichanical music boxes with much shorter sustain.

What I'm hearing now is that the tines sound more wooden than metal, both old and new code. I'm not sure what you could do to make them sound more metallic - perhaps it's merely that the sample rate is too low for the higher overtones of a metal tine. I suppose there might also be some part of the algorithm that imparts a wooden or metallic timbre. I do know that there are digital audio synthesizers with separate algorithms for wood, metal, glass, and nylon. I just don't know whether the core code changes or if it is merely a few parameter values that change between each of these sounds.
User avatar
rsdio
Developer
Developer
 
Posts: 1410
Joined: Sun Feb 28, 2010 10:53 pm
Location: Seattle

Re: Music Box / Wavetable Synthesizer / DDS

Postby rsdio » Tue Apr 17, 2012 5:29 am

Markus Gritsch wrote:Yes, you are right. I also thought about this, and the current implementation does not accout for this, i.e. triggering a new note of the same pitch will get another envelope on a new oscillator running.

I assume that you have a finite number of oscillators, and that a new note starts by picking an oscillator before making any changes. In other words, if more notes are sounding than there are oscillators, then something has to be dropped (the oldest note?). If that is the case, then you could modify that section of code to compare the pitch and pick a running oscillator if the pitch is the same. Of course, if you're really fancy then you could have one oscillator per note, like a real music box, but I bet that would require too much cpu (or too much optimization in assembly!).

EDIT: I see that you have 64 notes (or only 32 if not optimized by the compiler). I don't have the patience to count precisely, but there might be 72 tines on the latest music box link you provided. Since most synthesizers have some intelligence in the voice allocation algorithm, it might be worth a little extra effort to try a few changes.
User avatar
rsdio
Developer
Developer
 
Posts: 1410
Joined: Sun Feb 28, 2010 10:53 pm
Location: Seattle

Re: Music Box / Wavetable Synthesizer / DDS

Postby Markus Gritsch » Tue Apr 17, 2012 5:43 am

The sustain-part of the waveform is a pure sine wave, without any over-tones. Surprisingly this approximation sounds *quite* like a music box tone. Of course it could be improved by using more sample-memory and include several real samples for different pitch-ranges. However, my task here was not to rebuild a professional sounding sampler, but to have some minimalistic implementation which sounds good enough.

In the original posting I already wrote that 64 oscillators are used. With this amount of potentially simultaneous playing notes the oldest ones have already ended their sustain-envelope before they get reused by more recent notes. This is true for both example tunes.
User avatar
Markus Gritsch
Sr. Member
Sr. Member
 
Posts: 298
Joined: Tue Feb 09, 2010 6:54 am

Re: Music Box / Wavetable Synthesizer / DDS

Postby rsdio » Wed Apr 18, 2012 9:07 pm

Markus Gritsch wrote:The sustain-part of the waveform is a pure sine wave, without any over-tones. Surprisingly this approximation sounds *quite* like a music box tone. Of course it could be improved by using more sample-memory and include several real samples for different pitch-ranges. However, my task here was not to rebuild a professional sounding sampler, but to have some minimalistic implementation which sounds good enough.

My favorite hobby is sound synthesis, so forgive me for being so detailed. The sine sustain is perfect, most harmonics have died by the time the attack is done.

I think that the only reason the tines sound "wooden" is that the low frequencies are under-sampled. The higher notes sound very metallic to me, and quite good.

In the original posting I already wrote that 64 oscillators are used. With this amount of potentially simultaneous playing notes the oldest ones have already ended their sustain-envelope before they get reused by more recent notes. This is true for both example tunes.

Not to be too picky, but have you confirmed this? It seems that you could analyze the MIDI file to see how many simultaneous notes are playing. That would be very easy without considering the sustained notes, and maybe not even that difficult if you calculated the end of the note based on duration. Then again, you could just alter your firmware to turn on an LED any time a note is started on an oscillator that hasn't finished sustain, and that would be definitive.
User avatar
rsdio
Developer
Developer
 
Posts: 1410
Joined: Sun Feb 28, 2010 10:53 pm
Location: Seattle

Re: Music Box / Wavetable Synthesizer / DDS

Postby Markus Gritsch » Thu Apr 19, 2012 1:02 am

rsdio wrote:Not to be too picky, but have you confirmed this?


Having everything I say being questioned it getting a bit tiresome. Of course I have tested how many oscillators were necessary to not cut off any sustain region. Otherwise I would not say so.

May I suggest that you please take a look at the source code the next time before raising another speculation? It's everything there. For example in dds/dds.py line 1951 and 1976 the testing for truncation is done.
User avatar
Markus Gritsch
Sr. Member
Sr. Member
 
Posts: 298
Joined: Tue Feb 09, 2010 6:54 am

Re: Music Box / Wavetable Synthesizer / DDS

Postby rsdio » Thu Apr 19, 2012 12:27 pm

Markus Gritsch wrote:
rsdio wrote:Not to be too picky, but have you confirmed this?

Having everything I say being questioned it getting a bit tiresome. Of course I have tested how many oscillators were necessary to not cut off any sustain region. Otherwise I would not say so.

May I suggest that you please take a look at the source code the next time before raising another speculation? It's everything there. For example in dds/dds.py line 1951 and 1976 the testing for truncation is done.

I tried to apologize in advance for all of the questions, but I guess I did not make that clear.

My involvement with this project is at a very high level, and I don't really have the time to read the source code for every interesting project out there. That much work would feel like a code review, which would be a significant endeavor. I had hoped that we could discuss this at a high level and that you would be interested in the discussion. You always have the option of ignoring me :-)

Having not seen the source, I made the assumption that the music file was separate from the source code. In other words, I didn't think that it would be possible to count to number of simultaneous notes in the "song" based on the source code alone. I figured something like a MIDI file was being used. At any rate, I would not easily be able to analyze the polyphony based on source code, whereas it would be more likely to find an existing tool that would read a MIDI file.

Primarily, though, I thought you were at least somewhat interested in figuring out why the sound is slightly off. On the one hand, you say you're not worried about perfect quality - which is certainly fine - but at the same time it seems like there might be the possibility to discover an easy way to improve the quality without a lot of effort. Based on what I hear, if you could somehow increase the sample rate of the lower notes, then I think they'd sound as good as the higher notes. But admittedly that might require a change to the algorithm. Again, the high frequencies sound very realistic (to my ears) when compared to a mechanical music box.
User avatar
rsdio
Developer
Developer
 
Posts: 1410
Joined: Sun Feb 28, 2010 10:53 pm
Location: Seattle

Re: Music Box / Wavetable Synthesizer / DDS

Postby Markus Gritsch » Thu Apr 19, 2012 1:47 pm

rsdio wrote:Primarily, though, I thought you were at least somewhat interested in figuring out why the sound is slightly off.


That's because
A. The sustain part of a real music box is certainly no pure sine wave, but does contain overtones to some degree.
B. When picking a metal-pin in a real music box, all the other pins get excitet a bit due to mechanical and acoustic coupling. Similar to the stings of guitar or in a piano.
C. A real music box has a resonant-body.

None of the above stuff is taken care of, so it will certainly not sound like a real music box which never was my intention anyways. I did it the other way round: I tried how this extremely short pick-sound attack-waveform together with the pure sine-wave sustain part sounded, and it was surprisingly similar to a music box. Maybe I shouldn't have included the term music box in the title of this posting ;)

rsdio wrote:Based on what I hear, if you could somehow increase the sample rate of the lower notes, then I think they'd sound as good as the higher notes.


All notes are sampled at the same sample rate. This is how DDS works. In fact the lower notes are an even more perfect sine wave than the higher ones, for which fewer samples from the basic waveform can be taken to achieve the higher frequency. Maybe you perceive the higher notes more metallic due to more missing sample values from the sine wave. Who knows.

For more information read the Wikipedia entry about DDS or try to understand the source code. Here you have it, I suggested it again ;)
User avatar
Markus Gritsch
Sr. Member
Sr. Member
 
Posts: 298
Joined: Tue Feb 09, 2010 6:54 am

Re: Music Box / Wavetable Synthesizer / DDS

Postby BrianGriffin » Mon Apr 30, 2012 4:07 am

Dear Markus,

I like the port of that project to the PIC32. It's amazing. Keep it up.

If you put it in a wooden box and that magnetic plastic ballerina inside, you can actually fool someone that this is the real thing! :)
BrianGriffin
Newbie
Newbie
 
Posts: 15
Joined: Mon Apr 30, 2012 3:54 am
Location: Kuala Lumpur

Re: Music Box / Wavetable Synthesizer / DDS

Postby Nogginboink » Fri May 11, 2012 5:14 pm

I realize this thread is a bit old, but I'm trying to understand the code and how this project works. For the functionality you get out of it, the project is remarkably simple, both in hardware and in software. I'm quite impressed.

Is the PWM module simply being used as a crude DAC? I'm used to seeing an RC low-pass filter on the output of the PWM when this is done; does this circuit simply do away with the filter? Or is the PWM being used for some other purpose entirely?

Second question: what's the math behind the TICKS_LIMIT definition? I expected to see a regular interrupt in which the oscillators are updated, but it's done entirely within the while(true){} loop inside main(). Did instruction counting come into play here? Does TICKS_LIMIT have to change when OSCILLATOR_COUNT changes?

I'm going to see if I have any PIC32 parts on my workbench when I get home and if so, play with this. This is a really slick project and I want to understand how the darned thing works.
Nogginboink
Newbie
Newbie
 
Posts: 4
Joined: Tue Sep 21, 2010 10:47 pm

Re: Music Box / Wavetable Synthesizer / DDS

Postby Markus Gritsch » Sun May 13, 2012 2:16 pm

Nogginboink wrote:Is the PWM module simply being used as a crude DAC? I'm used to seeing an RC low-pass filter on the output of the PWM when this is done; does this circuit simply do away with the filter?

Yes, the PWM is used as a DAC. Since the speaker itself has a cutoff frequency, and the PWM frequency of 39062 Hz is way above this frequency, there is no need for a RC filter.

Nogginboink wrote:Second question: what's the math behind the TICKS_LIMIT definition? I expected to see a regular interrupt in which the oscillators are updated, but it's done entirely within the while(true){} loop inside main(). Did instruction counting come into play here? Does TICKS_LIMIT have to change when OSCILLATOR_COUNT changes?

No instruction counting. The loop over all oscillators has to be finished before the next sample must be written to the PWM register. So if OSCILLATOR_COUNT is reduced, nothing has to be changed. If it is increased, the sample rate must be reduced. After every PWM update, a tick counter is increased. TICKS_LIMIT is there to advance to the next time event of the midi file.
User avatar
Markus Gritsch
Sr. Member
Sr. Member
 
Posts: 298
Joined: Tue Feb 09, 2010 6:54 am

Re: Music Box / Wavetable Synthesizer / DDS

Postby ondeugd » Fri Jun 21, 2013 3:10 am

It's an old post but I'm trying to get some answers anyway.
Too cool a project to give up now :-)!

Your code is explicitely disabling jtag (JTAGEN = off in DEVCFG0).
My programmer is using the jtag interface, so I only could get the code in the pic by changing the hex to have JTAGEN = on. the jtag pins have nothing to do with the pins that are used by your code, so I assumed this would be allright.

Wired the whole thing like shown in the schematic, and attached my oscilloscope to pin 26, but the thing just doesn''t seem to be doing anything however.

Tried to find out from the datasheets etc if the enabling of the jtag interface is messing up the working of your code, but can't find anything. I'm not the best pic programmer by far though, only had some leds blinking on the pic32 till now, so I might be missing something...

So could you please shed a little light on this? Any chance my changed JTAGEN setting is messing my thing up?
And to be clear: just hooking up the battery should get the thing running wouldn't it?
ondeugd
Newbie
Newbie
 
Posts: 1
Joined: Fri Jun 21, 2013 1:59 am

Re: Music Box / Wavetable Synthesizer / DDS

Postby yerpa58 » Mon Jun 24, 2013 2:29 pm

to ondeudg,

I recently built a version of this project, too. I'm using a PICkit3 to program. I tried turning JTAG=ON in the code, and it still ran just fine. My board only runs at 40 MHz, though, probably due to the wrong kind of capacitor on pin 20. To make it run, I had to change the FPLLODIV = DIV_1 line to be FPLLODIV = DIV_2, and also changed OSCILLATOR_COUNT from 64 down to 32.

I also had to use compiler optimization level 1 or higher to get good fidelity.

Then it ran, one octave lower and half speed, but still a very cool project.
yerpa58
Newbie
Newbie
 
Posts: 1
Joined: Mon Jun 24, 2013 1:59 pm

Previous

Return to Project logs