From: Bill on
Hi, I've to write a function like this:

____________________
function outsnd = cctsnd(filein1, filein2, fileout)

that takes three strings with the names of three sound files: two input
and one output file, e.g.
outsnd = cctsnd('input1.wav','input2.wav','output.wav');

The two input sound files may have different sampling frequencies Fs1 and Fs2.

Read the sample data of filein1 into an array snd1.
Read the sample data of filein2 into an array snd2.

Up- or down-sample array snd2 and put the result in a new array called nsnd2.
Up-sampling means that new elements are added by copying some elements at regular increments of the array index, so that the array becomes bigger. Down-sampling means that some elements are removed at
regular increments of the array index, such that the array becomes smaller.
Up- or down-sample the array snd2 in such a way that when the result nsnd2 is played at a sampling frequency Fs1, it sounds like playing snd2 at sampling frequency Fs2.
Hint: the up- or down-sampling factor is equal to the ratio of the sampling frequencies Fs2 and Fs1.
For the implementation of up- or down-sampling use triplet index notation (1:step:end)

Concatenate the arrays snd1 and nsnd2 and put the result in a new array called outsnd.
This array specifies the samples of the output sound. Play it and write it to a file
fileout with sampling frequency Fs1.
____________________

Does anybody know how I can code this:

"Up- or down-sample the array snd2 in such a way that when the result nsnd2 is played at a sampling frequency Fs1, it sounds like playing snd2 at sampling frequency Fs2."

Thanks in advance
From: Bill on
Nobody has any idea how to fix this?
From: us on
On Mar 30, 5:45 pm, "Bill " <Billjans...(a)hotmail.com> wrote:
> Nobody has any idea how to fix this?

CSSMers - in general - have lots of ideas...
however, the perennial:
what have YOU done so far to solve YOUR particular problem...

us
From: Walter Roberson on
Bill wrote:

> Up-sampling means that new elements are added by copying some elements
> at regular increments of the array index, so that the array becomes
> bigger. Down-sampling means that some elements are removed at
> regular increments of the array index, such that the array becomes smaller.
> Up- or down-sample the array snd2 in such a way that when the result
> nsnd2 is played at a sampling frequency Fs1, it sounds like playing snd2
> at sampling frequency Fs2.

The task can only be accomplished by copying or removing samples if you use a
fairly loose interpretation of "sounds like".

Consider even a very simple case of a single period of a sine wave, and
doubling the samples. In order for the double-length version to sound the
same, you need to go from sine(((1:N)/N)*2*Pi) to sine(((1:2*N)/(2*N)*2*Pi) --
adding new samples that are sine() of the points half-way inbetween the
original points. As sine() is continuous, you cannot achieve the same effect
by copying existing samples: if you were to copy every original sample once
beside itself, you would end up with the right number of samples and
-approximately- the right shape, but the result would not be continuous (e.g.,
the differential of it would not be cos()).

When you upsample or downsample in the manner described in your assignment,
you introduce or lose harmonics (or both) -- and if any of those harmonics are
in the range from about 400 Hz to 12000 Hz, then to the average human ear, the
results will NOT "sound the same".

(When I was in my early 20's and had access to a sound synthesis and recording
studio, I tested myself and found that I could hear up to 17600 Hz, which was
quite good hearing indeed. I suspect, though, that the subsequent decades have
taken a very measurable toll on my upper range -- though I do seem to still be
better than average for my age range.)