My Project

- Página principal
- Clases
- Archivos

- Lista de archivos
- Miembros de los ficheros

wavesound.h
1 #ifndef WAVESOUND_H
2 #define WAVESOUND_H
3
4 #include <QtMultimedia/QAudioBuffer>
5 #include <QtMultimedia/QAudioFormat>
6 #include <QFile>
7 #include <iostream>
8 #include <QByteArray>
9
10 using namespace std ;
11
12 class WaveSound
13 {
14 private:
15 QByteArray header;
16 QAudioFormat format;
17 QByteArray wavBuffer;
18 QAudioBuffer *qab;
19
20 public:
21
22 WaveSound()
23 {
24 qab = NULL ;
25 format.setSampleSize(16);
26 format.setSampleRate(44100);
27 format.setChannelCount(2);
28 format.setCodec("audio/pcm");
29 format.setByteOrder(QAudioFormat::LittleEndian);
30 format.setSampleType(QAudioFormat::SignedInt);
31 }
32
33 QAudioBuffer::S16S * getAudioSamples(QString filename)
34 {
35 QFile inputFile;
36
37 inputFile.setFileName(filename);
38 inputFile.open(QIODevice::ReadOnly);
39 header = inputFile.read(44) ; // Wav header file is normally 44 bytes
40
41 wavBuffer = inputFile.readAll();
42 inputFile.close();
43
44 if(qab != NULL){
45 delete qab ;
46 }
47 qab = new QAudioBuffer(wavBuffer, format);
48
49 return qab->data<QAudioBuffer::S16S>();
50 }
51
52 void writeNewAudioFile(QString filename)
53 {
54 QByteArray outBuffer;
55 QFile outputFile;
56
57 outputFile.setFileName(filename);
58 outputFile.open(QIODevice::WriteOnly);
59 outBuffer.setRawData((char *) qab->data(), qab->byteCount() );
60
61 outputFile.write(header);
62 outputFile.write(outBuffer);
63 outputFile.close();
64 }
65
66 int frameCount()
67 {
68 return qab->frameCount();
69 }
70
71
72 ~WaveSound(){
73 if(qab != NULL){
74 delete qab ;
75 qab = NULL;
76 }
77 }
78
79 };
80 #endif // WAVESOUND_H
std
WaveSound
Definition: wavesound.h:12