summaryrefslogtreecommitdiff
path: root/rotord/rotor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/rotor.cpp')
-rw-r--r--rotord/rotor.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp
index 2ab5734..53ba33b 100644
--- a/rotord/rotor.cpp
+++ b/rotord/rotor.cpp
@@ -431,9 +431,31 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process
*/
- http://www.gamedev.net/topic/624876-how-to-read-an-audio-file-with-ffmpeg-in-c/
+ //http://www.gamedev.net/topic/624876-how-to-read-an-audio-file-with-ffmpeg-in-c/
// Initialize FFmpeg
+
+ //this seems to only read a certain percentage of the sound file? - different for wav and mp3
+ //peculiar, because the data comes in as frames and we just read them until all are done
+ //is it possible that thhe problem lies with the drawing process only?
+ //wav sees 6/10 waves and mp3 sees 3.5/10
+ //could this be an aliasing effect i.e. from reading the sample format wrong?
+ //I think probably not?
+
+ //every format combination seems to miss a different number of samples
+ //I don't understand how different formats would make the samples seem to truncate?
+ //unless its an aliasing type thing?
+
+ //wave.mp3 reads 16.409% of 160913
+ //wave.wav reads 29.706% of 882044
+
+
+
av_register_all();
+
+ //??
+ //avcodec_init();
+ avcodec_register_all();
+ //??
AVFrame* frame = avcodec_alloc_frame();
if (!frame)
@@ -497,6 +519,12 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process
std::cout << "Couldn't open the context with the decoder" << std::endl;
return false;
}
+
+ //
+ // why is the file truncated???
+ //if(codecContext->codec->capabilities & CODEC_CAP_TRUNCATED) codecContext->codec->capabilities|=CODEC_FLAG_TRUNCATED;
+ //
+ //
av_dump_format(formatContext, 0, 0, false); //avformat.h line 1256
int samples = ((formatContext->duration + 5000)*codecContext->sample_rate)/AV_TIME_BASE;
@@ -514,10 +542,19 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process
AVPacket packet;
av_init_packet(&packet);
int sample_processed=0;
+
+ bool diag=true;
// Read the packets in a loop
- while (av_read_frame(formatContext, &packet) == 0)
+ while (true)
+ //while(sample_processed<samples)
{
+ int ret=av_read_frame(formatContext, &packet);
+ if (ret<0) {
+ cerr << "finished with code "<<ret <<(ret==AVERROR_EOF?" ,EOF":"")<<endl;
+ break;
+ }
+ //av_read_frame(formatContext, &packet); //hangs once the packets have been read
if (packet.stream_index == audioStream->index)
{
// Try to decode the packet into a frame
@@ -535,12 +572,20 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process
// the audio data, so I won't add any junk here that might confuse you. Typically, if I want to find
// documentation on an FFmpeg structure or function, I just type "<name> doxygen" into google (like
// "AVFrame doxygen" for AVFrame's docs)
+
+ //av_get_channel_layout_string (char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
+
+ if (diag) {
+ cerr << "first frame: "<<bytes << ", "<<frame->nb_samples<<" samples in "<<av_get_sample_fmt_name(frame->format)<<" format with channel layout "<<frame->channel_layout<< std::endl;
+ diag=false;
+ }
//std::cout << "Got a frame: bytes " << bytes << ", "<<frame->nb_samples<<" samples"<<std::endl;
//now we can pass the data to the processor(s)
for (auto p: processors) {
sample_processed=p->process_frame(frame->data[0],frame->nb_samples);
}
+
mutex.lock();
progress=((double)sample_processed)/samples;
mutex.unlock();
@@ -568,6 +613,9 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process
mutex.unlock();
}
}
+
+ cerr << "finished processed: "<<sample_processed << " samples of "<<samples<<" , "<<((double)sample_processed*100)/samples<<"%"<< std::endl;
+
// Clean up!
av_free(frame);
@@ -638,6 +686,8 @@ void audio_thumbnailer::init(int _channels,int _bits,int _samples) {
channels=_channels;
bits=_bits;
samples=_samples;
+
+ cerr << "init audio thumbnailer with "<<channels<<" channels, "<<samples<<" samples of "<< bits<<" bits."<<endl;
samples_per_column=samples/width;
@@ -647,10 +697,10 @@ void audio_thumbnailer::init(int _channels,int _bits,int _samples) {
scale=1.0/offset;
}
int audio_thumbnailer::process_frame(uint8_t *_data,int samples_in_frame){
- //begin by processing remaining samplesthread 4
- //samples per column could be larger than a frame! (probably is)
+ //begin by processing remaining samples
+ //samples per column could be larger than a frame! (probably is)
//but all we are doing is averaging
- int bytes=(bits>>3);
+ int bytes=(bits>>3);
int stride=channels*bytes;
int in_sample=0;
while (in_sample<samples_in_frame&&column<width) {