It is currently Sun Jul 22, 2018 3:44 pm

 All times are UTC - 7 hours

 Page 2 of 2 [ 19 posts ] Go to page Previous  1, 2
 Print view Previous topic | Next topic
Author Message
 Post subject: Posted: Tue May 05, 2009 5:15 pm

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Raspy = you need to use some kind of interpolation (especially with the wave channel, as it has lots of super-sonic harmonics). Start with linear; simplest to implement, most bang for-the-buck.

Top

 Post subject: Posted: Wed May 06, 2009 12:09 am

Joined: Wed Apr 22, 2009 12:47 am
Posts: 9
Do you mean linearly interpolate the playback buffer when the sound api is requesting it?

So for example the SDL Api periodically requests a copy of the playback buffer for it to play. Is this when I perform the linear interpolation on the buffer?

When you say perform linear interpolation I assume you mean pick two indexes in the playback buffer and then interpolate those values between. I.E. if you picked every 5 indexes then the first interpolation would calculate the values in the playback buffer between indexes 0 and 4. And then between 4 and 9 etc.

Thanks again for your help mate. In a matter of days I've gone from knowing nothing about sound emulation to getting results, which is thanks to yourself and tepples.

Top

 Post subject: Posted: Wed May 06, 2009 3:22 am

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4056
He's talking about how you generate the square wave. Not talking about linear interpolation as in blur filters you see in image editors.

A square wave goes up and down repeatedly.

For example, let's say we have a 50% duty cycle square wave at Middle C.
440*2^(-9/12) Hz (~261.625 Hz)

We want to emit a wave at 44100 Hz.

Each stretch where it stays up or down is about 84.28 samples long. (44100 / 261.625 / 2)

There are some really bad ways to do sound:
* Round 84.28 to the nearest integer and use that as the period instead. This changes the frequency. Don't do this.
* Emit 84 samples, have .28 leftover, emit 84 more samples, have .56 leftover, emit 84 samples, have .84 leftover, emit 85 samples, have .12 leftover. This sounds really bad, the period of the wave is not consistent.

Then there's an easy way to get decent sound:
* Emit 84 samples, use the 0.28/1.0 fraction to determine what fractional amplitude to output next. Then emit 84 more samples, and use the 0.56/1.0 fraction to determine what to output next. This is the linear interpolation he was talking about. You output fraction * OLD + (1.0-fraction) * NEW every time you would need to output a fractional length sample.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Top

 Post subject: Posted: Thu May 07, 2009 12:00 am

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
Dwedit wrote:
He's talking about how you generate the square wave. Not talking about linear interpolation as in blur filters you see in image editors.

Actually, just what you see in image editors when scaling an image down a lot (though they tend to use bicubic rather than bilinear). In this case, the Game Boy sound hardware can generate sound at around a 4 MHz sampling rate, while the sound card probably only plays it at around 0.048 Mhz (48000 Hz). So if you want to graphically see what linear interpolation of 1/60 a second would be like, make a grayscale image that's 1 pixel high and 69905 pixels wide, fill it with some rectangles that are each fairly wide, then resize it horizontally to 800 pixels.

That's the ultimate goal. But as Dwedit describes, you don't have to literally do such a laborous resize, examining every input sample, as long as you generate the same final result. Since the input isn't a waveform which constantly changes every 1 four millionth of a sample (usually), other approaches are more efficient. A simple first approach is to generate samples at a lower rate that's still around 4 times that of the output rate, then do the above "rescaling" to get the final rate. You'll deal with about 22 times less data than dealing with the full rate.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 2 of 2 [ 19 posts ] Go to page Previous  1, 2

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki