• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sample-rate conversion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sample-rate conversion


  • Subject: Re: Sample-rate conversion
  • From: Volker Runkel <email@hidden>
  • Date: Wed, 4 Feb 2004 09:33:09 +0100

Hi Jens,

I assume your problem is that you have aliasing effects on account of the slopes from hi/lo and lo/hi (containing half a dirac delta function). Square waves produce harmonics (every 2nd = 1st 3rd 5th...) which get mirrored (by aliasing effects) into your sound range. It might be helpful to lowpass filter your signal at 22 kHz before transforming it.

BTW: Where do you get the 3.5 MHz sampled signal from ?

Please ask back if the explanation is not easy to understand, but it is still early in the morning :-)
Volker & Wolfram - just biologists :-)


- - - - - - - - - - - - - ------ ---- ---- --- -- - - - - - - - - - - - - - - -
Dipl.-Biol. Volker Runkel
Lehrstuhl f. Zoologie II www.biologie.uni-erlangen.de/zoo2
Staudtstr. 5 Telefon: 09131-85 28788
91058 Erlangen email@hidden
- - - - - - - - - - - - - ------ ---- ---- --- -- - - - - - - - - - - - - - - -

Am 04.02.2004 um 06:31 schrieb Jens Bauer:

Hi all,

I just wrote a program, which needs to convert a sample-rate from approx. 3.5MHz resolution to 44100Hz resolution.
The signal that is sampled, is in the hearable range, but I ran into a problem that some of you most likely recognize.
When I have a "pure tone", and it's converted, I can hear another tone, which is of a lower frequency, and the amplitude is somewhat lower.
Is there an easy/simple way of getting rid of these extra tones ?

I pull around 79 or 80 samples from the 3.5MHz signal add them up, averaging them by dividing them by # of samples read (say 80), then I multiply them by the playback volume, and store them in the left+right channel (mono).

The signal I am converting, is a square signal, which can be either hi or lo.

Here's the most important part of my 'playback' code:

OSStatus playbackCallback(AudioDeviceID device, const AudioTimeStamp *now, const AudioBufferList *input_data, const AudioTimeStamp *input_time, AudioBufferList *output_data, const AudioTimeStamp *output_time, void *client_data)
{
register int channels;
register int frames;
register float left;
register float right;
register float *new_data;
register float volume;
register MyUserInfo *userInfo;
register float samples;
register float ear;
register float countDown;

userInfo = (MyUserInfo *)client_data;

new_data = (float *)(output_data->mBuffers[0].mData);
channels = output_data->mBuffers[0].mNumberChannels;
frames = (output_data->mBuffers[0].mDataByteSize / sizeof(float)) / channels;

volume = userInfo->volume;
countDown = userInfo->lastCountDown; // restore saved countDown value

while(frames--)
{
ear = 0.0;
samples = 80.0; // (never mind this default-value!)
if(userInfo->sampleRate > 0.0)
{
samples = (3500000.0 / userInfo->sampleRate);
}
countDown += samples;
samples = 0.0;
while(countDown-- >= 1.0)
{
samples++;
ear =+ ear_state(userInfo->tape) ? volume : -volume;
}
ear /= samples;
left = ear;

right = left;
*new_data++ = left;
*new_data++ = right;
}
userInfo->lastCountDown = countDown; // save fractional part of countDown for next time

return(kAudioHardwareNoError);
}

Earlier, I used integers for the counters. I hoped to get rid of some of the tones, by using floating point counters (to get the division more precise), but I don't hear the big difference. :/ (Note: countDown is saved for next time the callback is invoked)


I tried looking at the output it generates (by dumping it to a file), and this looks nice (I haven't analyzed the frequencies, as I'm not experienced enough for this yet).
After that, I tried to connect the audio out to the audio in jack (speaker->microphone), and when I used an oscilloscope program on the playback program, I got a minor shock. I didn't imagine that my data could be *that* much distorted. A bunch of high frequencies are living on the 'lo' and 'hi' edges.
I do not see these in the file I dumped.
There is a strange thing. I tried using Audio Hijack on the output (before it gets into the oscilloscope), and using lowpass filters, I got rid of very much noise. (This confuses me quite a bit, because when I output pure data, how can Audio Hijack make them cleaner??? -Is this because I output square waves rather than sine waves?)

Love,
Jens
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

References: 
 >Sample-rate conversion (From: Jens Bauer <email@hidden>)

  • Prev by Date: Re: multithreaded mixer
  • Next by Date: Re: Sample-rate conversion
  • Previous by thread: Re: Sample-rate conversion
  • Next by thread: Re: Sample-rate conversion
  • Index(es):
    • Date
    • Thread