/*****************************************************************************
* PCM.c:
*****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004 the VideoLAN team
* $Id$
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
//Takes sound data from wherever and hands it back out.
//Returns PCM Data or spectrum data, or the derivative of the PCM data
-#include <stdlib.h>
-#include <stdio.h>
+#include <inttypes.h>
double **PCMd; //data structure to store PCM data PCM[channels][maxsamples]
int maxsamples; //size of PCM buffer
void initPCM(int samples)
{
- int i;
+ int i;
//Allocate memory for PCM data buffer
PCMd = (double **)malloc(2 * sizeof(double *));
PCMd[0] = (double *)malloc(samples * sizeof(double));
PCMd[1] = (double *)malloc(samples * sizeof(double));
-
+
maxsamples=samples;
new=0;
int i,j;
int samples=512;
- for(i=0;i<samples;i++)
- {
- j=i+start;
- PCMd[0][j%maxsamples]=(PCMdata[0][i]/16384.0);
- PCMd[1][j%maxsamples]=(PCMdata[1][i]/16384.0);
- }
-
+ for(i=0;i<samples;i++)
+ {
+ j=i+start;
+ PCMd[0][j%maxsamples]=(PCMdata[0][i]/16384.0);
+ PCMd[1][j%maxsamples]=(PCMdata[1][i]/16384.0);
+ }
+
- // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]);
+ // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]);
start+=samples;
start=start%maxsamples;
void getPCM(double *PCMdata, int samples, int channel, int freq, double smoothing, int derive)
{
int i,index;
-
+
index=start-1;
if (index<0) index=maxsamples+index;
PCMdata[0]=PCMd[channel][index];
-
+
for(i=1;i<samples;i++)
{
index=start-1-i;
if (index<0) index=maxsamples+index;
-
+
PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1];
}
-
+
//return derivative of PCM data
if(derive)
{
for(i=0;i<samples-1;i++)
- {
- PCMdata[i]=PCMdata[i]-PCMdata[i+1];
- }
+ {
+ PCMdata[i]=PCMdata[i]-PCMdata[i+1];
+ }
PCMdata[samples-1]=0;
}
if (freq) rdft(samples, 1, PCMdata, ip, w);
-
+
}
//getPCMnew
int getPCMnew(double *PCMdata, int channel, int freq, double smoothing, int derive, int reset)
{
int i,index;
-
+
index=start-1;
if (index<0) index=maxsamples+index;
PCMdata[0]=PCMd[channel][index];
-
+
for(i=1;i<new;i++)
{
index=start-1-i;
if (index<0) index=maxsamples+index;
-
+
PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1];
}
-
+
//return derivative of PCM data
if(derive)
{
for(i=0;i<new-1;i++)
- {
- PCMdata[i]=PCMdata[i]-PCMdata[i+1];
- }
+ {
+ PCMdata[i]=PCMdata[i]-PCMdata[i+1];
+ }
PCMdata[new-1]=0;
}