IGNORED

# Replaying sound samples with the sound chip

## Recommended Posts

I know we discussed this a while ago, but I can't remember the nuts-and-bolts of it. Too much bloody Forth swilling around my brain!

Assume I already have the 8 bit sampled data. So, how do I go about replaying it using the sound chip.

I can remember that for best results one sets all three sound channels to some nominal (high) frequency, and simply controls the volume of the channels.

My question is: How do I use the sample data to manipulate the volume? What's the technique? At first, I though it was as simple as mask every bit of a byte of sample data, and if the bit is a 1, set the volume for all 3 channels to max, and if it's a zero, then set the volume for all three channels to 0.

However, if you had a sample that just happened to be 11111111 (is that even possible? I don't know??) then you'd actualy hear... nothing. So I think I've got the wrong end of the stick somewhere...

Any insights greatly appreciated.

Thanks

Mark

##### Share on other sites

I know we discussed this a while ago, but I can't remember the nuts-and-bolts of it. Too much bloody Forth swilling around my brain!

Assume I already have the 8 bit sampled data. So, how do I go about replaying it using the sound chip.

I can remember that for best results one sets all three sound channels to some nominal (high) frequency, and simply controls the volume of the channels.

My question is: How do I use the sample data to manipulate the volume? What's the technique? At first, I though it was as simple as mask every bit of a byte of sample data, and if the bit is a 1, set the volume for all 3 channels to max, and if it's a zero, then set the volume for all three channels to 0.

However, if you had a sample that just happened to be 11111111 (is that even possible? I don't know??) then you'd actualy hear... nothing. So I think I've got the wrong end of the stick somewhere...

Any insights greatly appreciated.

Thanks

Mark

I goofed around a while back and saw the same issue. I don't know if this is correct but the solution I came up with was to look at it in terms of pops and non pops (volume that is.) a 1 indicated spiking the volume to max and immediately turning it off where as a zero indicates just leaving the volume off during the cycle.

##### Share on other sites

If you are dealing with 1-bit PCM samples, then a '1' bit is "high" and a '0' bit is "low". "1111111" indicates a flat-line. It would be the same as a stream of "255" bytes in 8-bit samples, and so, correct, you wouldn't hear anything.

A long time ago I wrote a digitizer that sampled single bits from the cassette port and played back 1-bit audio that way. Although I lost the digitizer my TMNT game for Missing Link used it to play back some music on the title page. I did upload the digitizer package to the Ottawa TI User Group BBS, but I don't know if those files are available anywhere anymore.

It's very important to have an exactly regular playback loop. That means that the codepath taken for a '1' bit needs to be the same number of cycles as the codepath taken for a '0' bit. If you don't, it actually introduces still more noise - your ears are amazingly sensitive to tiny variations. (Alternately, you use a hardware timer to manage the playback, but we are somewhat lacking on high precision timers on the 4A). It should still be recognizable, though.

4-bit playback works just as easily, though of course it takes more data. Technically most PCM waveforms are linear, and the TI sound chip is logarithmic, but it'll be very recognizable even if you don't account for that (just a bit quiet).

When you get more advanced, you can use that logarithmic factoid to do better than 4-bit resolution by mixing channels. I haven't done this one yet myself, though I've heard the result out of the MSX sound chip (which is similar), and it's impressive. There's a thread somewhere in the ColecoVision section here on doing the same thing there - I can't remember if there is source but there is examples to listen to.

One small downside is it'll never sound perfect. The sound chip will always be outputting a square wave at around 48kHz, and that will interfere some with the playback. But it's impressive how decent it CAN sound. I don't know if any emulator can handle sampled sound right now - Classic99 can't (it could before I redid the sound chip, heh..).

I did a quick example this afternoon. ZIP contains source, object codes, and a disk image ready to go:

samples.zip

##### Share on other sites

Hey thanks man! I'll check your code out right now.

What if the sample data consists of samples of freqency? As far as I know, the data from the ADC is sampling frequency, rather than amplitude? Does that change the technique? (Am I even using the right nomenclature here?).

I'm very sorry - I have NO experience of this stuff. I'm just helping someone who is using TurboForth to sample audio. It's working (the sampling) - he's getting ~2000 samples a second using just vanilla Forth code. He was talking about building a DAC to be able to replay the sampled data. I thought I should be able to get TF to replay the sampled data through the sound chip (using assembly code, not Forth code).

Mark

##### Share on other sites

Hey thanks man! I'll check your code out right now.

What if the sample data consists of samples of freqency? As far as I know, the data from the ADC is sampling frequency, rather than amplitude? Does that change the technique? (Am I even using the right nomenclature here?).

I'm very sorry - I have NO experience of this stuff. I'm just helping someone who is using TurboForth to sample audio. It's working (the sampling) - he's getting ~2000 samples a second using just vanilla Forth code. He was talking about building a DAC to be able to replay the sampled data. I thought I should be able to get TF to replay the sampled data through the sound chip (using assembly code, not Forth code).

Unless you have some strange ADC, it's measuring amplitude. More accurately, it's likely measuring voltage. Frequency converters exist, but don't really work well enough for recording audio (and even then, they usually output a voltage which would have to run through a traditional ADC anyway!) Beside that, if he was getting frequency instead of amplitude, a DAC won't play it back without also coding a tone generator.

So I would say that it's extremely unlikely that you have frequency samples. I /can/ say with some certainty that there are no commonly used audio formats in modern use that store frequency data instead of amplitude, and playing that data back would be difficult on any machine. This is because most audio contains numberous overlaid frequencies - you can't boil it down to a single frequency at a set point in time unless it's just a single pure tone. If you've ever watched an FFT running, you'll see how complex sounds are in frequency space.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.