Giter VIP home page Giter VIP logo

clownresampler's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jfolker alexeyavb

clownresampler's Issues

Input can cause clipped/ distorted audio and asserts

Hi pal,

Thank you very much for your work on this library; it's great to finally have an up and coming public domain resampler.

I've been testing it out: and I'm finding that when input samples either come close to or reach the 0DB threshhold, the output can be either clipped/ wrapped around, or can cause this assert to fail:
CLOWNRESAMPLER_ASSERT(normalised_sample >= -0x7FFF && normalised_sample <= 0x7FFF);

This audio does have some distortion (it is a digitization of an old tape and the source material had some quality issues). The file is normalized and does span the entire valid range of sixteen-bit signed samples. If you resample it from 48000HZ down to 44100HZ, you will hear a very noticeable clip a few seconds into the file. If you pass it through the resampler at a 1/1 ratio (48K in, 48K out), it triggers the aforementioned assert.

The source file can be found here:
https://cloud.caturria.ca/s/PJ2XwipeLF5xdZF

The resampled file is here:
https://cloud.caturria.ca/s/eFJSAeYqaPDKP59

My code is below (if the formatting sucks, please forgive me: as a totally blind person I've always found code formatting to be a struggle). It uses DR_Wav to read the source file and write the result to a wave file.

#include <stdio.h>
#include <stdlib.h>
#define CLOWNRESAMPLER_IMPLEMENTATION
#define CLOWNRESAMPLER_KERNEL_RADIUS 3

#include "clownresampler.h"
#include <stdio.h>
#define DRWAV_IMPLEMENTATION

#include "dr_wav.h"
#define OUT_RATE 48000

int main(int argc, const char argv[])
{

unsigned int channels_in;//number of channels in the wav file.
unsigned int sample_rate_in;//sample rate of the wav file.
drwav_uint64 total_frames_in;//length of the input wav file in PCM frames.
ClownResampler_Precomputed precomputed;
ClownResampler_LowLevel_State state;
size_t input_frame_count;
size_t output_frame_count;
drwav wav;//for writing the output to a wav file.
drwav_data_format out_format;//describes the format of the output wav file.
short* source;//contains the input data.
size_t out_buffer_size;//size of the output buffer that will be given to ClownResampler.

source = drwav_open_file_and_read_pcm_frames_s16("Lullaby improved.wav", &channels_in, &sample_rate_in, &total_frames_in, NULL);
assert(source != NULL);
out_buffer_size = ((double)total_frames_in / (double)sample_rate_in) * (double)OUT_RATE;//in PCM frames.
short* dest = (short*)malloc(out_buffer_size * sizeof (short) * channels_in);
assert(dest != NULL);

ClownResampler_Precompute(&precomputed);
ClownResampler_LowLevel_Init(&state, channels_in, sample_rate_in, OUT_RATE);
input_frame_count = total_frames_in - 128;//I know this is lazy: but instead of padding the beginning and end, I'm just allowing the first and last few samples to be sacrificed for the sake of a simple demo.
output_frame_count = total_frames_in;

ClownResampler_LowLevel_Resample(&state, &precomputed, source, &input_frame_count, dest, &output_frame_count);
output_frame_count = (out_buffer_size - output_frame_count);//convert number of frames not used to number of frames used.
input_frame_count = (total_frames_in - input_frame_count);

															 //Set the parameters and output a wav file containing the result.

out_format.bitsPerSample = 16;
out_format.channels = 2;
out_format.container = drwav_container_riff;
out_format.format = DR_WAVE_FORMAT_PCM;
out_format.sampleRate = 44100;

drwav_init_file_write(&wav, "clownresampler_distortion.wav", &out_format, NULL);
drwav_write_pcm_frames(&wav, output_frame_count, dest);
drwav_uninit(&wav);
drwav_free(source, NULL);
free(dest);

printf("%d PCM frames in and %d PCM frames out.", total_frames_in, output_frame_count);
getchar();

}

Thank you for your attention to this. I look forward to being able to use this library once the final kinks have been ironed out.

Kind regards,

Jordan.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.