med

music editor
git clone git://git.kocotian.pl/cbms.git
Log | Files | Refs

commit d3015cbf4d929c50467f3bdd8c8a639e6de351ea
parent 5917fcb2c61ab233041f014b49accc863af7a6c7
Author: kocotian <kocotian@kocotian.pl>
Date:   Sun,  6 Dec 2020 16:22:49 +0100

fixes, reversing included, volume

Diffstat:
Mmed | 0
Mmed.c | 25+++++++++++++++++++++----
Mutil.c | 7+++++++
Mutil.h | 1+
4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/med b/med Binary files differ. diff --git a/med.c b/med.c @@ -29,8 +29,9 @@ static void savef32(char *filename, Wave wave, char endianness); static void selectwave(Wave *waves, size_t waven, int *selwav, char *l); static void shell(Wave **waves, size_t *waven); static void wavedump(Wave wave); +static void wavevolume(Wave *wave, char *l); static float wavelength(size_t wavesize, int sampleRate, int channels); -static void wavereverse(Wave *wave, size_t beginning, size_t ending); +static void wavereverse(Wave *wave); static void writewave(Wave wave, char *name); static void usage(void); @@ -41,7 +42,7 @@ static void changewavselection(Wave *wave, char isRight, char *l) { size_t *val = isRight ? &(wave->rightSelection) : &(wave->leftSelection); - char secs = l[strlen(l) - 1] == 's' ? 1 : 0; + char secs = (l[strlen(l) - 1] == 's'); switch (*l) { case '=': /* set to X number of samples/seconds */ *val = strtol(++l, NULL, 10) * wave->channels * (secs ? wave->sampleRate : 1); @@ -63,8 +64,12 @@ docommand(Wave **waves, size_t *waven, int *selwav, char *l) { if (*selwav < 0) puts("err: no selected wave"); - else if(!strcmp(l, "dump")) + else if(!strcmp("dump", l)) wavedump((*waves)[*selwav]); + else if(!strcmp("rev", l)) + wavereverse(&((*waves)[*selwav])); + else if(!strcmpt("vol/", l, '/')) + wavevolume(&((*waves)[*selwav]), l + 4); else puts("?"); } @@ -296,6 +301,16 @@ wavedump(Wave wave) wave.wave - wptr, *(wave.wave++)); } +static void +wavevolume(Wave *wave, char *l) +{ + int iter = wave->leftSelection == -1 ? -1 : wave->leftSelection - 1; + float voldiff; + voldiff = strtof(l, NULL); + while (++iter < (wave->rightSelection == -1 ? wave->wsize : wave->rightSelection)) + wave->wave[iter] *= voldiff; +} + static float wavelength(size_t wsize, int sampleRate, int channels) { @@ -303,8 +318,10 @@ wavelength(size_t wsize, int sampleRate, int channels) } static void -wavereverse(Wave *wave, size_t beginning, size_t ending) +wavereverse(Wave *wave) { + size_t beginning = wave->leftSelection == -1 ? 0 : wave->leftSelection - 1, + ending = wave->rightSelection == -1 ? wave->wsize : wave->rightSelection; size_t bufsiz = ending - beginning; float *wavebuf = malloc(sizeof(float) * bufsiz); size_t iter = -1; diff --git a/util.c b/util.c @@ -41,3 +41,10 @@ strrep(char *str, char src, char dest) while (*(++str)) if (*str == src) *str = dest; } + +int +strcmpt(const char *l, const char *r, const char t) +{ + for (; *l==*r && *l && *l!=t; l++, r++); + return *(unsigned char *)l - *(unsigned char *)r; +} diff --git a/util.h b/util.h @@ -7,3 +7,4 @@ void die(const char *fmt, ...); void *ecalloc(size_t nmemb, size_t size); void strrep(char *str, char src, char dest); +int strcmpt(const char *l, const char *r, const char t);