]> git.sesse.net Git - c64tapwav/commitdiff
Use float samples internally.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 9 Mar 2015 23:18:56 +0000 (00:18 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 9 Mar 2015 23:19:11 +0000 (00:19 +0100)
audioreader.cpp
audioreader.h
decode.cpp
interpolate.h

index f0d07d8c08741acde3d13197f50503128a5bcdc9..e133afce9a24c704ec47e56d8cd2072bbe0f0ff4 100644 (file)
@@ -50,25 +50,25 @@ struct AVSampleDeleter {
        }
 };
 
-void convert_samples(SwrContext *swr, int sample_rate, const uint8_t **data, int nb_samples, std::vector<int16_t> *samples)
+void convert_samples(SwrContext *swr, int sample_rate, const uint8_t **data, int nb_samples, std::vector<float> *samples)
 {
        int max_out_samples = nb_samples + swr_get_delay(swr, sample_rate);
        if (max_out_samples == 0) {
                return;
        }
        uint8_t *output;
-       av_samples_alloc(&output, nullptr, 1, max_out_samples, AV_SAMPLE_FMT_S16, 0);
+       av_samples_alloc(&output, nullptr, 1, max_out_samples, AV_SAMPLE_FMT_FLT, 0);
        std::unique_ptr<uint8_t, AVSampleDeleter> output_deleter(output);
 
        int out_samples = swr_convert(swr, &output, max_out_samples, data, nb_samples);
        if (out_samples > 0) {
-               const int16_t* start = reinterpret_cast<const int16_t *>(output);
-               const int16_t* end = start + out_samples;
+               const float* start = reinterpret_cast<const float *>(output);
+               const float* end = start + out_samples;
                samples->insert(samples->end(), start, end);
        }
 }
 
-int decode_packet(const char *filename, AVCodecContext *codec_ctx, SwrContext *swr, AVFrame *audio_frame, AVPacket *packet, int *got_frame, std::vector<int16_t> *samples)
+int decode_packet(const char *filename, AVCodecContext *codec_ctx, SwrContext *swr, AVFrame *audio_frame, AVPacket *packet, int *got_frame, std::vector<float> *samples)
 {
        *got_frame = 0;
        int len1 = avcodec_decode_audio4(codec_ctx, audio_frame, got_frame, packet);
@@ -88,7 +88,7 @@ int decode_packet(const char *filename, AVCodecContext *codec_ctx, SwrContext *s
 
 }  // namespace
 
-bool read_audio_file(const char *filename, std::vector<int16_t> *samples, int *sample_rate)
+bool read_audio_file(const char *filename, std::vector<float> *samples, int *sample_rate)
 {
        av_register_all();
 
@@ -141,7 +141,7 @@ bool read_audio_file(const char *filename, std::vector<int16_t> *samples, int *s
        }
        SwrContext *swr = swr_alloc_set_opts(
                nullptr,
-               AV_CH_LAYOUT_MONO, AV_SAMPLE_FMT_S16, codec_ctx->sample_rate,
+               AV_CH_LAYOUT_MONO, AV_SAMPLE_FMT_FLT, codec_ctx->sample_rate,
                codec_ctx->channel_layout, codec_ctx->sample_fmt, codec_ctx->sample_rate,
                0, nullptr);
        std::unique_ptr<SwrContext, SwrContextDeleter> swr_deleter(swr);
index 47bb8f50b02a5db702e0fa1b474e8a8e136a53fa..c654b612dbe3d7782feaa03569eb84df50183e39 100644 (file)
@@ -5,6 +5,6 @@
 
 #include <stdint.h>
 
-bool read_audio_file(const char *filename, std::vector<int16_t> *samples, int *sample_rate);
+bool read_audio_file(const char *filename, std::vector<float> *samples, int *sample_rate);
 
 #endif  // !defined(_AUDIOREADER_H)
index 8ed2f1b4e7714c9d3a8776aec9e26e30ee142b41..5bb3b2c5edbe58f5b4c4b2bb7df3cc72a91fa101 100644 (file)
@@ -20,7 +20,7 @@
 #define SYNC_TEST_TOLERANCE 1.10
 
 // between [x,x+1]
-double find_zerocrossing(const std::vector<short> &pcm, int x)
+double find_zerocrossing(const std::vector<float> &pcm, int x)
 {
        if (pcm[x] == 0) {
                return x;
@@ -107,7 +107,7 @@ double calibrate(const std::vector<pulse> &pulses) {
 int main(int argc, char **argv)
 {
        make_lanczos_weight_table();
-       std::vector<short> pcm;
+       std::vector<float> pcm;
        int sample_rate;
        if (!read_audio_file(argv[1], &pcm, &sample_rate)) {
                exit(1);
index f9aeb110060a0501b1e79255fa0edbab2a156ecb..c71110b37d71950c9b02b47950ff8d7c1d93bcac 100644 (file)
@@ -29,9 +29,9 @@ inline double lanczos_weight(double x)
 extern double lanczos_table[LANCZOS_RADIUS * LANCZOS_RESOLUTION];
 void make_lanczos_weight_table();
 
-inline double lanczos_weight_table(double x)
+inline double lanczos_weight_table(float x)
 {
-       int table_id = lrintf(fabs(x) * LANCZOS_RESOLUTION);
+       int table_id = lrintf(fabsf(x) * LANCZOS_RESOLUTION);
        if (table_id >= LANCZOS_RADIUS * LANCZOS_RESOLUTION) {
                return 0.0;
        }