473,857 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

low and high frequency of an audio file

How to get the frequency of an audio file and how to separate the low
and high frequency of an audio file

Apr 6 '07 #1
7 4064
Udhay wrote:
How to get the frequency of an audio file and how to separate the low
and high frequency of an audio file
I don't know. It isn't a C++ problem, try a group where audio files are
topical (there are many different formats of audio file).

--
Ian Collins.
Apr 6 '07 #2
Udhay wrote:
How to get the frequency of an audio file and how to separate the low
and high frequency of an audio file
Look at "Discrete Fourier Transform" and the implementations of a "Fast
Fourier Transform".

Here is some code I toyed with - I lifted it from somewhere, I don't
know exactly where and then I templateized it a little.

The FFT is done in the complex number space.... You could also look up
the DCT (discrete cosine transform) which I think operates in the real
number space but it's not as accurate - I really don't know much about
DCT's.
#define PI 3.1415926535897 932384626

inline long revbin_update(l ong r,long n)
{
do {
n=n>>1;
r=r^n;
} while ((r&n)==0);
return r;
}

template <typename TranType>
inline void revbin_permute( TranType *a,long n)
{
if (n<=2) return;
long r=0;
for (long x=1; x<n; x++)
{
r=revbin_update (r,n);
if (r>x) swap(a[x],a[r]);
}
}

template <typename TranType>
TranType omega(double theta)
{ return TranType(cos(th eta),sin(theta) ); }

template <int is, typename TranType>
void fft(TranType *a, long ldn)
// O(N log N)
//
// a[] is the TranType input data set, lsb in 0 and msb in N
// ldn is the power of 2 which contains the entire data set, try to
// align the data to a power of 2 by padding with zeroes.
// is is the direction of the transform, +1 = forward, -1 = backward
//
// result is a[]
{
long n=1 << ldn;

revbin_permute( a,n);
for (long ldm=1; ldm<=ldn; ldm++)
{
long m=1 << ldm;
long mh=m/2;

for (long j=0; j<mh; j++)
{
TranType e=omega<TranTyp e>(is*2*PI*j/m);

for (long r=0; r<=n-m; r+=m)
{
TranType u=a[r+j];
TranType v=a[r+j+mh]*e;

a[r+j]=(u+v);
a[r+j+mh]=(u-v);
}
}
}
}

template <typename TranType>
void fft_convolution (TranType *x,TranType *y, long n)
// x[], y[] are the two input TranType data sets.
// n is the power of 2 which contains the entire data set.
//
// result is y[]
{
long pw=1 << n;

fft<1>(x,n); // forward transform of x[]
fft<1>(y,n); // forward transfomr of y[]

for (int i=0; i<pw; i++)
y[i]=y[i]*x[i]; // element wise multiplication

fft<-1>(y,n); // backward transform of y[]

for (int i=0; i<pw; i++)
y[i]=y[i]/TranType(pw,0); // normalize
}

#include <complex>
/// example of use
int main()
{
static std::complex<do uble a[1<<21];

// revbin_permute( a, 1<<21 );
fft<1>( a, 21 );
}
Apr 6 '07 #3
On Apr 6, 5:53 am, "Udhay" <udhyakum...@gm ail.comwrote:
How to get the frequency of an audio file and how to separate the low
and high frequency of an audio file
as someone else has pointed out, performing a fourier transform on the
raw data is what you need. Instead of trying to build your own
fourier transform there are ones available in the Intel Performance
Primitives Library that will do everything that you need. I've used
them for a while now and find them very fast and accurate.

Flamingo

Apr 6 '07 #4
Dnia Thu, 05 Apr 2007 21:53:13 -0700, Udhay napisa³(a):
How to get the frequency of an audio file and how to
separate the low and high frequency of an audio file
NTG, but maybe it would help you:
1. Think about what is frequency. It's an occurence of
something over some particular time. The more often
it occurs, the higher is that frequency.
2. Sound consists from waves. Every sound can be decomposed
to its component waves, which are sines.
3. A lowpass filter is lowering the amplitude for higher
frequency components, and doesn't change the amplitude
for lower frequency components.
4. Audio file stores values of the amplitude in particular
moments of time [samples].
5. A wave is the change in ampliture over time.

So, use advices of the other posters and use FFT to decompose
sound to its frequency components [spectral analysis], deamplify
the frequencies you don't want and compose your sound back again
using only the frequency components you want [they're sines,
you know].

--
SasQ
Apr 6 '07 #5
SasQ wrote:
Dnia Thu, 05 Apr 2007 21:53:13 -0700, Udhay napisał(a):
.....
>
So, use advices of the other posters and use FFT to decompose
sound to its frequency components [spectral analysis], deamplify
the frequencies you don't want and compose your sound back again
using only the frequency components you want [they're sines,
you know].
No no ... if you want to create a filter (filter out a certain set of
frequencies) then create a low-pass/high-pass/band-pass filter. There
is no need to do it in the frequency domain. FFT's are relatively
expensive computationally .
Apr 6 '07 #6
Dnia Fri, 06 Apr 2007 14:18:50 -0700, Gianni Mariani napisa³(a):
>So, use advices of the other posters and use FFT to decompose
sound to its frequency components [spectral analysis], deamplify
the frequencies you don't want and compose your sound back again
using only the frequency components you want [they're sines,
you know].

No no ... if you want to create a filter (filter out a certain
set of frequencies) then create a low-pass/high-pass/band-pass
filter. There is no need to do it in the frequency domain.
FFT's are relatively expensive computationally .
Oh, I didn't know that can be done better. Can you tell me
something more about it? [maybe on priv, if it's NTG here].

--
SasQ
Apr 7 '07 #7
SasQ wrote:
Dnia Fri, 06 Apr 2007 14:18:50 -0700, Gianni Mariani napisał(a):

>>>So, use advices of the other posters and use FFT to decompose
sound to its frequency components [spectral analysis], deamplify
the frequencies you don't want and compose your sound back again
using only the frequency components you want [they're sines,
you know].

No no ... if you want to create a filter (filter out a certain
set of frequencies) then create a low-pass/high-pass/band-pass
filter. There is no need to do it in the frequency domain.
FFT's are relatively expensive computationally .


Oh, I didn't know that can be done better. Can you tell me
something more about it? [maybe on priv, if it's NTG here].
I don't remember all the details. You can probably find enough
information if you google for "discrete low pass filter" or somthing
like that.
Apr 7 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2502
by: Bruce Bon | last post by:
The class below is intended to play a Sun audio file (.au) in the background while the main thread, which is servicing a GUI, continues without impact. It doesn't work. For a sound file that takes 3-5 seconds to play, the main thread hangs for that long. I have run this many times, with changes in printouts and insertion of strategic sleeps to try to make sure that the player thread gives up control, but apparently the call to...
1
2702
by: laredotornado | last post by:
Hello, I want to play an audio file embedded on my page by clicking on an audio image and the page change to a new page. Is there a cross-browser Javascript way to do this? Right now the code I have is ... <html> <head> <title>Dictionary: homeostasis</title> <link href="liveink.css" type="text/css" rel="stylesheet"/> </head>
0
2353
by: laredotornado | last post by:
Hello, I want to play an audio file by clicking on an audio icon and not having the page switch out underneath. Right now the code I have is ... <html> <head> <title>Dictionary: homeostasis</title> <link href="liveink.css" type="text/css" rel="stylesheet"/> </head> <body>
5
2598
by: Shelly | last post by:
I had a problem with uploading images in that some files did not have a type of "image/something" from the $_FILES which I used for my verification. Someone (THANK YOU) suggested using getimagesize() which has the third element in the returned array being a number representing the image type. That worked perfectly for me, enabling me to check that it was, indeed, an image file that I had uploaded. Now I ask if there is a similar...
4
6061
by: Gary Morrison | last post by:
I need to create a lot of fairly-short audio files from the concatenation of a lot of even shorter audio files. I'd like to control that from a Perl script. The audio files would presumably be AIFF or WAV files, preferable AIFF. Do any of you know of Perl commands to accomplish this? Specifically, * A call to create and open a new, empty AIFF or WAV file, * A call to append onto the end of that open audio file the audio content of...
3
4817
by: abrtlt | last post by:
I would like to have a web page in which, when the user clicks on any of several specific elements, a specific audio file is played, without reloading the page. The specific audio file name is obtained from a PHP script (accessing a MySQL database) that could be called using XMLHttpRequest and JavaScript would write in a "div" tag an "embed and play" HTML tag containing the audio file name. I am not sure this would work, as the embed tag...
6
2002
by: Quentin | last post by:
Hi, I want to save an audio stream into a circular file so that I only keep say the last hour's audio. Can anybody help? Cheers, Quentin
13
4912
by: anil.rita | last post by:
When the user chooses an AV file to play, based upon the type of file, I want to use the default installed media player to play it. I am wondering if this is a good way - any alternatives, suggestions or improvements? if( wmv file) document.write("<OBJECT id=Player classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 height="354" width="479">
1
1751
by: =?Utf-8?B?Qm9iQWNoZ2lsbA==?= | last post by:
I am using Windows Media Player to play my half second audio files one after the other using the code below... My problem comes when I play a second audio file immediately after the first one stops sometimes on slower computers the audio on the second file gets truncated on the beginning of playing the second file. What can I do to minimize this truncation of audio? Right now I am having to add 1 second of blank audio to the beginning...
0
11083
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10711
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7940
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.