-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathoffline3.cpp
executable file
·49 lines (40 loc) · 1.94 KB
/
offline3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <malloc.h>
#include "Superpowered.h"
#include "SuperpoweredDecoder.h"
#include "SuperpoweredSimple.h"
#include "SuperpoweredAnalyzer.h"
// EXAMPLE: reading an audio file, processing the audio and returning with some features detected
int main(int argc, char *argv[]) {
Superpowered::Initialize("ExampleLicenseKey-WillExpire-OnNextUpdate");
// Open the input file.
Superpowered::Decoder *decoder = new Superpowered::Decoder();
int openReturn = decoder->open("test.m4a");
if (openReturn != Superpowered::Decoder::OpenSuccess) {
printf("\rOpen error %i: %s\n", openReturn, Superpowered::Decoder::statusCodeToString(openReturn));
delete decoder;
return 0;
};
// Create the analyzer.
Superpowered::Analyzer *analyzer = new Superpowered::Analyzer(decoder->getSamplerate(), decoder->getDurationSeconds());
// Create a buffer for the 16-bit integer audio output of the decoder.
short int *intBuffer = (short int *)malloc(decoder->getFramesPerChunk() * 2 * sizeof(short int) + 16384);
// Create a buffer for the 32-bit floating point audio required by the effect.
float *floatBuffer = (float *)malloc(decoder->getFramesPerChunk() * 2 * sizeof(float) + 16384);
// Processing.
while (true) {
int framesDecoded = decoder->decodeAudio(intBuffer, decoder->getFramesPerChunk());
if (framesDecoded < 1) break;
// Submit the decoded audio to the analyzer.
Superpowered::ShortIntToFloat(intBuffer, floatBuffer, framesDecoded);
analyzer->process(floatBuffer, framesDecoded);
};
analyzer->makeResults(60, 200, 0, 0, false, false, false, false, false);
printf("\rBpm is %f, average loudness is %f db, peak volume is %f db.\n", analyzer->bpm, analyzer->loudpartsAverageDb, analyzer->peakDb);
// Cleanup.
delete decoder;
delete analyzer;
free(intBuffer);
free(floatBuffer);
return 0;
}