Thread: Changing wave freq

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    Changing wave freq

    I understand how wave files work, and I know how to read & write & play them (even raw), but I'm not sure how to change the frequency of the wave file's contents without changing the play speed. When ever I make a low freq, the talking becomes real slow. I know why this happens, but how do I maintain speed and change the freq? I've googled several times, but to no avail.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You would have to split the speech into segments that have the same frequency, then replace a segment of (say) 400Hz with one of equal length but at 300Hz.

    You need to have a read about "signal processing" and such things. Fourier Transform is probably another subject that may need some reading...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Why would you want to change the frequencies in the file? You can alter how they sound by altering the playback frequency. You shouldn't change the frequencies in the file and should treat those as your baseline.

  4. #4
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    if i understand what you want to do correctly,what you're referring to is called timestretching.

    a basic way to do it is with grain looping. a grain is a small subset of the file. to timestretch it, the grain is repeated either fully or partially to achieve the desired length of time.

    e.g. to half the speed, you'd play each grain twice.

    you may have to do some interpolation and/or more involved logic to avoid transients, but the basic principle is just that simple.

  5. #5
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    this forum is excellent for all your audio questions

    http://www.kvraudio.com/forum/viewforum.php?f=33

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by m37h0d View Post
    if i understand what you want to do correctly,what you're referring to is called timestretching.

    a basic way to do it is with grain looping. a grain is a small subset of the file. to timestretch it, the grain is repeated either fully or partially to achieve the desired length of time.

    e.g. to half the speed, you'd play each grain twice.

    you may have to do some interpolation and/or more involved logic to avoid transients, but the basic principle is just that simple.
    That's pretty much what I described, although I also suggested putting the boundaries of the "grains" at frequency changes.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    Quote Originally Posted by matsp View Post
    That's pretty much what I described, although I also suggested putting the boundaries of the "grains" at frequency changes.

    --
    Mats
    yes, that's pretty similar, but i don't think any spectral analysis is required. you should be able to do it all in real time with interpolation.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by m37h0d View Post
    yes, that's pretty similar, but i don't think any spectral analysis is required. you should be able to do it all in real time with interpolation.
    One way of duplicating a grain is concatenate it with the negation of its reverse. The reversal makes sure the result is smooth to zero'th order -- the negation makes sure it's smooth to first order.

    So, to time-stretch a grain G into N grains, you concatenate:

    G + ~R(G) + G + ~R(G) ... <N times>

    Where ~(G) is negation, R(G) is reversal.

    Smaller grains lead to less noise (due to lack of higher order smoothness) -- however, smaller grains allow for less spectral richness. Larger grains allow richness but produce more noise...

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    141
    Are you talking about resampling the waveform or actually frequency shifting it?
    Resampling would cause the waveform to sound slower or faster when you played it back unless you changed the sample rate of player globally.

    frequency shifting would cause a low note to become a higher note or vice a versa depending on which direction you did the shifting. Frequency shifting would not slow down or speed up the play back rate. For an audio signal you will have an alias problem which may require a band pass filter to fix. There are a couple of ways to do this. One way would be to apply a Hilbert transform, which is a complex filter that keeps the upper half of the spectrum. Then multiply the output of the Hilbert transform by a frequency shifter of the form exp(2*pi * F * t), where F is the shift frequency. Then keep the real part.

    As for duplicating grains, that sounds like another effect entirely and I'm not sure I understand it's purpose. The main reason for time reversing and concatening would be to avoid a discontinuity in the waveform if you wanted to lengthen the data record.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by SevenThunders View Post
    Are you talking about resampling the waveform or actually frequency shifting it?
    Neither, I think. The topic is time stretching, which means preserving both sampling rate and frequency while stretching in time. Not something which can be achieved by changing effective sampling rates, resampling, or simple interpolation.

    It's easy to get something that "kinda works," it's hard to get something that really sounds good.

  11. #11
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    Quote Originally Posted by brewbuck View Post
    One way of duplicating a grain is concatenate it with the negation of its reverse. The reversal makes sure the result is smooth to zero'th order -- the negation makes sure it's smooth to first order.

    So, to time-stretch a grain G into N grains, you concatenate:

    G + ~R(G) + G + ~R(G) ... <N times>

    Where ~(G) is negation, R(G) is reversal.

    Smaller grains lead to less noise (due to lack of higher order smoothness) -- however, smaller grains allow for less spectral richness. Larger grains allow richness but produce more noise...
    very interesting. makes sense.

    i'm not familiar with the term 'negation', i assume ~G = -1*G?

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by m37h0d View Post
    yes, that's pretty similar, but i don't think any spectral analysis is required. you should be able to do it all in real time with interpolation.
    Not necessary, but it will help avoiding "burps and blips" where you copy a low-to-high volume or high-to-low volume transition so that you two consecutive audible transitions. The risk of this is of course dependent on the size of the grain.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by m37h0d View Post
    very interesting. makes sense.

    i'm not familiar with the term 'negation', i assume ~G = -1*G?
    Exactly.

  14. #14
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Sony Sound Forge does this but it is far from perfect. Also most SoundBlaster series of cards can do time stretching on the hardware but I'm sure it's not the best quality. You would need to google for DSP algorithms and read through a lot of material to get this working correctly. Even then I'm sure someone who does have it working well isn't going to just publish it on the web b/c it's probably part of some high end audio software.

  15. #15
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    I think the OP is askign hwo to take a 5 second clip of a mans voice and increase teh frequency of the audio so it soudns like a womans voice, but maintains the same tempo.

    You need to break the sample into its constituent frequencies and then assign them to highr frequencies. So if a sample contains say 1000 2000 and 4000 Hz you then set the output sample to contain 1500, 3000, and 6000 Hz. Fourier analysis is probably the easiest way to do this, but that isnt to imply that it will be easy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  2. writing a wave file from my wave samples
    By Queatrix in forum Windows Programming
    Replies: 2
    Last Post: 12-31-2005, 11:54 PM
  3. Changing windows without changing?
    By Lionmane in forum Windows Programming
    Replies: 7
    Last Post: 10-19-2005, 11:41 AM
  4. Processing a sine wave file
    By subdene in forum C++ Programming
    Replies: 2
    Last Post: 07-12-2004, 03:04 PM
  5. Help open wave file in Borland C++ plz
    By toa2k in forum C++ Programming
    Replies: 1
    Last Post: 01-22-2004, 07:55 AM