]> git.sesse.net Git - vlc/blobdiff - modules/visualization/galaktos/PCM.c
Don't print a message a malloc failed.
[vlc] / modules / visualization / galaktos / PCM.c
index 0ebee5f55f16d544c11e7c9cae4d1d2fb46bd1b5..82162f3f332ed30671d10d3a2b2a2147b49fe2ef 100644 (file)
 //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>
 
+#include "fftsg.h"
+
 double **PCMd;    //data structure to store PCM data  PCM[channels][maxsamples]
 int maxsamples;   //size of PCM buffer
 int start;        //where to add data next
@@ -48,13 +52,13 @@ int new;          //how many new samples
 
 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;
 
@@ -83,15 +87,15 @@ void addPCM(int16_t PCMdata[2][512])
   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;
@@ -113,28 +117,28 @@ void addPCM(int16_t PCMdata[2][512])
 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;
      }
 
@@ -142,7 +146,7 @@ void getPCM(double *PCMdata, int samples, int channel, int freq, double smoothin
    if (freq) rdft(samples, 1, PCMdata, ip, w);
 
 
+     
 }
 
 //getPCMnew
@@ -154,28 +158,28 @@ void getPCM(double *PCMdata, int samples, int channel, int freq, double smoothin
 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;
      }