commit 9df6e90d85baf5881dcead5b5b46c9a236ad5590
parent 3c319ebe96c8391b6cd5bb346b541559d1df58cf
Author: Mark McCurry <[email protected]>
Date: Fri, 5 Jun 2009 18:37:31 -0400
Added iostream, strings, and proper indentation to Output/
OSSaudiooutput : added iostream
Recorder : added strings and fixed indentation
WAVaudiooutput : added strings and fixed indentation
Diffstat:
6 files changed, 65 insertions(+), 73 deletions(-)
diff --git a/src/Output/OSSaudiooutput.C b/src/Output/OSSaudiooutput.C
@@ -27,9 +27,12 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <iostream>
#include "OSSaudiooutput.h"
#include "../Misc/Util.h"
+#include "../globals.h"
+using namespace std;
OSSaudiooutput::OSSaudiooutput(){
int i;
@@ -44,7 +47,8 @@ OSSaudiooutput::OSSaudiooutput(){
snd_handle=open(config.cfg.LinuxOSSWaveOutDev,O_WRONLY,0);
if (snd_handle == -1) {
- fprintf(stderr,"ERROR - I can't open the %s .\n",config.cfg.LinuxOSSWaveOutDev);
+ cerr << "ERROR - I can't open the ";
+ cerr << config.cfg.LinuxOSSWaveOutDev << '.'<< endl;
return;
};
ioctl(snd_handle,SNDCTL_DSP_RESET,NULL);
diff --git a/src/Output/OSSaudiooutput.h b/src/Output/OSSaudiooutput.h
@@ -23,9 +23,8 @@
#ifndef OSS_AUDIO_OUTPUT_H
#define OSS_AUDIO_OUTPUT_H
-
-#include <sys/soundcard.h>
#include "../globals.h"
+
class OSSaudiooutput{
public:
OSSaudiooutput();
diff --git a/src/Output/Recorder.C b/src/Output/Recorder.C
@@ -20,26 +20,16 @@
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <sys/types.h>
#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
#include "Recorder.h"
-#include <sys/stat.h>
Recorder::Recorder(){
recordbuf_16bit=new short int [SOUND_BUFFER_SIZE*2];
status=0;
notetrigger=0;
- for (int i=0;i<SOUND_BUFFER_SIZE*2;i++){
- recordbuf_16bit[i]=0;
- };
+ for (int i=0;i<SOUND_BUFFER_SIZE*2;i++){
+ recordbuf_16bit[i]=0;
+ }
};
Recorder::~Recorder(){
@@ -47,16 +37,15 @@ Recorder::~Recorder(){
delete [] recordbuf_16bit;
};
-int Recorder::preparefile(char *filename_,int overwrite){
- if (!overwrite){
- struct stat fileinfo;
- int statr;
-
- statr = stat(filename_,&fileinfo);
- if(statr == 0) {//file exists
- return 1;
- };
- };
+int Recorder::preparefile(std::string filename_,int overwrite){
+ if (!overwrite){
+ struct stat fileinfo;
+ int statr;
+ statr = stat(filename_.c_str(),&fileinfo);
+ if(statr == 0) {//file exists
+ return 1;
+ }
+ }
if (!wav.newfile(filename_, SAMPLE_RATE,2)) return 2;
@@ -81,24 +70,24 @@ void Recorder::pause(){
int Recorder::recording(){
if ((status==2)&&(notetrigger!=0)) return(1);
- else return(0);
+ else return(0);
};
void Recorder::recordbuffer(REALTYPE *outl,REALTYPE *outr){
- int tmp;
- if (status!=2) return;
- for (int i=0;i<SOUND_BUFFER_SIZE;i++){
- tmp=(int)(outl[i]*32767.0);
- if (tmp<-32768) tmp=-32768;
- if (tmp>32767) tmp=32767;
- recordbuf_16bit[i*2]=tmp;
-
- tmp=(int)(outr[i]*32767.0);
- if (tmp<-32768) tmp=-32768;
- if (tmp>32767) tmp=32767;
- recordbuf_16bit[i*2+1]=tmp;
- };
- wav.write(SOUND_BUFFER_SIZE,recordbuf_16bit);
+ int tmp;
+ if (status!=2) return;
+ for (int i=0;i<SOUND_BUFFER_SIZE;i++){
+ tmp=(int)(outl[i]*32767.0);
+ if (tmp<-32768) tmp=-32768;
+ if (tmp>32767) tmp=32767;
+ recordbuf_16bit[i*2]=tmp;
+
+ tmp=(int)(outr[i]*32767.0);
+ if (tmp<-32768) tmp=-32768;
+ if (tmp>32767) tmp=32767;
+ recordbuf_16bit[i*2+1]=tmp;
+ };
+ wav.write(SOUND_BUFFER_SIZE,recordbuf_16bit);
};
void Recorder::triggernow(){
diff --git a/src/Output/Recorder.h b/src/Output/Recorder.h
@@ -22,7 +22,7 @@
#ifndef RECORDER_H
#define RECORDER_H
-
+#include <string>
#include "../globals.h"
#include "WAVaudiooutput.h"
@@ -32,7 +32,7 @@ class Recorder{
Recorder();
~Recorder();
- int preparefile(char *filename_,int overwrite);//returns 1 if the file exists
+ int preparefile(std::string filename_,int overwrite);//returns 1 if the file exists
void start();
void stop();
void pause();
diff --git a/src/Output/WAVaudiooutput.C b/src/Output/WAVaudiooutput.C
@@ -32,6 +32,7 @@ WAVaudiooutput::~WAVaudiooutput(){
};
bool WAVaudiooutput::newfile(string filename,int samplerate,int channels){
+ /**\todo Move this into the Constructor*/
close();//inchide un posibil fisier existent
file=fopen(filename.c_str(),"w");
if (!file) return false;
@@ -44,42 +45,42 @@ bool WAVaudiooutput::newfile(string filename,int samplerate,int channels){
};
void WAVaudiooutput::close(){
- if (file){
- unsigned int chunksize;
- rewind(file);
+ if (file){
+ unsigned int chunksize;
+ rewind(file);
- fwrite("RIFF",4,1,file);
- chunksize=sampleswritten*4+36;
- fwrite(&chunksize,4,1,file);
+ fwrite("RIFF",4,1,file);
+ chunksize=sampleswritten*4+36;
+ fwrite(&chunksize,4,1,file);
- fwrite("WAVEfmt ",8,1,file);
- chunksize=16;
- fwrite(&chunksize,4,1,file);
- unsigned short int formattag=1;//uncompresed wave
- fwrite(&formattag,2,1,file);
- unsigned short int nchannels=channels;//stereo
- fwrite(&nchannels,2,1,file);
- unsigned int samplerate_=samplerate;//samplerate
- fwrite(&samplerate_,4,1,file);
- unsigned int bytespersec=samplerate*2*channels;//bytes/sec
- fwrite(&bytespersec,4,1,file);
- unsigned short int blockalign=2*channels;//2 channels * 16 bits/8
- fwrite(&blockalign,2,1,file);
- unsigned short int bitspersample=16;
- fwrite(&bitspersample,2,1,file);
+ fwrite("WAVEfmt ",8,1,file);
+ chunksize=16;
+ fwrite(&chunksize,4,1,file);
+ unsigned short int formattag=1;//uncompresed wave
+ fwrite(&formattag,2,1,file);
+ unsigned short int nchannels=channels;//stereo
+ fwrite(&nchannels,2,1,file);
+ unsigned int samplerate_=samplerate;//samplerate
+ fwrite(&samplerate_,4,1,file);
+ unsigned int bytespersec=samplerate*2*channels;//bytes/sec
+ fwrite(&bytespersec,4,1,file);
+ unsigned short int blockalign=2*channels;//2 channels * 16 bits/8
+ fwrite(&blockalign,2,1,file);
+ unsigned short int bitspersample=16;
+ fwrite(&bitspersample,2,1,file);
+
+ fwrite("data",4,1,file);
+ chunksize=sampleswritten*blockalign;
+ fwrite(&chunksize,4,1,file);
- fwrite("data",4,1,file);
- chunksize=sampleswritten*blockalign;
- fwrite(&chunksize,4,1,file);
-
- fclose(file);
- file=NULL;
- };
+ fclose(file);
+ file=NULL;
+ }
};
void WAVaudiooutput::write(int nsmps,short int *smps){
if (!file) return;
- fwrite(smps,nsmps,4,file);
+ fwrite(smps,nsmps,4,file);
sampleswritten+=nsmps;
};
diff --git a/src/Output/WAVaudiooutput.h b/src/Output/WAVaudiooutput.h
@@ -20,7 +20,6 @@
#ifndef WAVOUTPUT_H
#define WAVOUTPUT_H
#include <string>
-#include <stdio.h>
class WAVaudiooutput{
public: