Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: fb39ca4 on December 22, 2013, 04:49:55 pm

Title: Methods For Playback of Waveform Audio
Post by: fb39ca4 on December 22, 2013, 04:49:55 pm
With the recent improvements in video compression I have made, it appears that I will have 500-550KB of space in Bad Apple which I can use for audio, which works out to 18kbits/s. Because of this, I want to try playing back waveform audio of the original song, rather than synthesized notes. What are the pros and cons of different methods used to play back 8 bit audio on 1 bit outputs used by other sound applications like RealSound and TruSound? I haven't found much information about how they work. I also found this algorithm (http://www.romanblack.com/btc_alg.htm), which encodes higher bit audio down to 1 bit by predicting the behavior of an RC filter, so how does it compare?
Title: Re: Methods For Playback of Waveform Audio
Post by: thepenguin77 on December 22, 2013, 07:35:45 pm
I've explained this many times before. I don't remember where and I don't feel like finding it, but there's a really good explanation out there somewhere. Probably in either the trusound or truvid threads.

The basic idea is that you need to use pulse width modulation to approximate different voltages. You're going to be flipping the link port 18,000 times per second. This means you're going to send 18,000 groups of ON OFF. Now, the timing of your ON OFF determines the approximate voltage. 50% ON 50% OFF is of course the middle voltage. 0 100, 33 67, 67 33, 100 0 gets you 2 bits of output with 4 possible positions. The more voltages you have the better it's going to sound obviously. I think in trusound I used something like 250 steps.

To finally play your music, just run through the data and output the correctly timed ON and OFF pulses. The main downside to this is that depending on how you implement it, it takes 30%-100% of the cpu power just to play music.

Title: Re: Methods For Playback of Waveform Audio
Post by: Juju on December 22, 2013, 08:32:17 pm
Yup, you'll want to use PWM.

When the port is ON during 1/88200 of a second, it's a 1 and when it's OFF it's a 0. Repeat in groups of 8 bits 11025 groups a second, convert your WAV to 11025 Hz, send the data down the link port in PWM and I think you'll get a decent rate.
Title: Re: Methods For Playback of Waveform Audio
Post by: Keoni29 on December 22, 2013, 08:57:19 pm
You can use pwm or you could use external hardware like a digital to analog converter with a 2 wire interface.
Title: Re: Methods For Playback of Waveform Audio
Post by: Juju on December 22, 2013, 09:15:43 pm
You can use pwm or you could use external hardware like a digital to analog converter with a 2 wire interface.
Most people will want to plug their headphones directly in the calc with a 2.5mm to 3.5mm converter or using an AM radio.
Title: Re: Methods For Playback of Waveform Audio
Post by: Lunar Fire on December 22, 2013, 10:21:07 pm
You have to see with the remaining program space you can use and the available processing power to determine at which rate you can play the audio. I honestly don't believe you will be able to play audio at 18 khZ, but this seems to be a starting point. You can lower the quality after if it slows down your program.

If I looked at your timing loop well, once it is done rendering a frame it waits for your 1/30th second to render the next. You will have to change your timing loop for it to process your waveform audio before waiting for the next frame. Basically here your goal will be to calculate your image and audio generation loops to have as few waiting time as possible between frames.
Title: Re: Methods For Playback of Waveform Audio
Post by: fb39ca4 on December 22, 2013, 10:53:27 pm
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?
Title: Re: Methods For Playback of Waveform Audio
Post by: calc84maniac on December 23, 2013, 01:38:05 pm
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?
Yes and yes. I would actually recommend using two crystal timer interrupts to do the audio output, the first repeating at the sample rate and the second scheduled by the first. As for the noise problem... I'm not sure exactly what you should do about that. I guess increasing the sample rate would be out of the question. (Well actually, you could perhaps reduce the audio quality to 6-bit or something, there's really a limit as to how accurate your PWM timing can be anyway)
Title: Re: Methods For Playback of Waveform Audio
Post by: thepenguin77 on December 23, 2013, 09:50:23 pm
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?

From my experience, 18KHz is about the minimum frequency you can use and not be able to hear it. If I moved my head around, I could hear doppler effects, but sitting still it sounded fine. I was 18 when I decided this, so take that as a reference because the younger you are, the higher the frequency you can hear. If you use 20KHz, you should be safe with all age groups.

Edit:
   Also, what really sucks when you start doing sound is that you find out that not all calculators run at the same clock rate. Your range is basically 14.5MHz - 17.0MHz
Title: Re: Methods For Playback of Waveform Audio
Post by: Keoni29 on December 24, 2013, 05:46:25 am
By using a simple audio filter you can filter out anything above a certain frequency.
Title: Re: Methods For Playback of Waveform Audio
Post by: Lunar Fire on December 26, 2013, 11:34:06 pm
So for PWM it will really be 36,000 writes to the link port per second? And if I am doing PWM at 18KHz, won't the noise from that be audible?

From my experience, 18KHz is about the minimum frequency you can use and not be able to hear it. If I moved my head around, I could hear doppler effects, but sitting still it sounded fine. I was 18 when I decided this, so take that as a reference because the younger you are, the higher the frequency you can hear. If you use 20KHz, you should be safe with all age groups.

Edit:
   Also, what really sucks when you start doing sound is that you find out that not all calculators run at the same clock rate. Your range is basically 14.5MHz - 17.0MHz

From what I learned in my classes, we can hear audio at frequencies from around 20Hz to 20 kHz. That's why audio is most of the time sampled at 44kHz (avoids aliasing). Around 18kHz will probably be fine for you. You might have a few audio glitches but anything under 44kHz will. As for the actual method of implementing it, I can't really help you. Sorry.