How to make audio sound better? (C + FFMpeg audio generation example) -


so found great c ffmpeg official example simplified:

#include <stdlib.h> #include <stdio.h> #include <string.h>  #ifdef have_av_config_h #undef have_av_config_h #endif  #include "libavcodec/avcodec.h" #include "libavutil/mathematics.h"  #define inbuf_size 4096 #define audio_inbuf_size 20480 #define audio_refill_thresh 4096  /*  * audio encoding example  */ static void audio_encode_example(const char *filename) {     avcodec *codec;     avcodeccontext *c= null;     int frame_size, i, j, out_size, outbuf_size;     file *f;     short *samples;     float t, tincr;     uint8_t *outbuf;      printf("audio encoding\n");      /* find mp2 encoder */     codec = avcodec_find_encoder(codec_id_mp2);     if (!codec) {         fprintf(stderr, "codec not found\n");         exit(1);     }      c= avcodec_alloc_context();      /* put sample parameters */     c->bit_rate = 64000;     c->sample_rate = 44100;     c->channels = 2;      /* open */     if (avcodec_open(c, codec) < 0) {         fprintf(stderr, "could not open codec\n");         exit(1);     }      /* codec gives frame size, in samples */     frame_size = c->frame_size;     samples = malloc(frame_size * 2 * c->channels);     outbuf_size = 10000;     outbuf = malloc(outbuf_size);      f = fopen(filename, "wb");     if (!f) {         fprintf(stderr, "could not open %s\n", filename);         exit(1);     }      /* encode single tone sound */     t = 0;     tincr = 2 * m_pi * 440.0 / c->sample_rate;     for(i=0;i<200;i++) {         for(j=0;j<frame_size;j++) {             samples[2*j] = (int)(sin(t) * 10000);             samples[2*j+1] = samples[2*j];             t += tincr;         }         /* encode samples */         out_size = avcodec_encode_audio(c, outbuf, outbuf_size, samples);         fwrite(outbuf, 1, out_size, f);     }     fclose(f);     free(outbuf);     free(samples);      avcodec_close(c);     av_free(c); }  int main(int argc, char **argv) {      /* must called before using avcodec lib */     avcodec_init();      /* register codecs */     avcodec_register_all();      audio_encode_example("test.mp2");      return 0; } 

how should sound like? may don't sounds awful =( how make audio generation sound better/ more interesting/ melodical in wary shourt way (no special functions how change code make sound better)?

if understand code correctly, should pure tone, or ascending tone (i'm not sure). either way won't sound nice. hear pure sine wave tones in nature - sound rather strident , harsh. things consider sound "musical" tend composed of many different frequencies.

as changing it, maybe various sound generation algorithms can use make pitch vary in terms of multiple sine waves.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -