Skip to content

Commit

Permalink
Imported Upstream version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MestreLion committed Oct 5, 2012
1 parent 274a3ab commit bff3cf0
Show file tree
Hide file tree
Showing 8 changed files with 808 additions and 562 deletions.
163 changes: 163 additions & 0 deletions WaveGain/WaveGain.icproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Intel C++ Project"
Version="11.1"
Name="WaveGain"
ProjectGUID="{0CD1B744-6DF0-4891-AC3D-130D38F56D3D}"
VCNestedProjectGUID="{519BA429-0A0D-44F3-98E0-0C47D9A45F70}"
VCNestedProjectFileName="WaveGain.vcproj">
<Configurations>
<Configuration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</Configuration>
<Configuration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files">
<File
RelativePath="..\audio.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\dither.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\gain_analysis.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\getopt.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\getopt1.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\main.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\recurse.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\wavegain.c">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="GeneralTool"
CompilerName="1"/>
</FileConfiguration>
</File>
</Filter>
</Files>
</VisualStudioProject>
73 changes: 59 additions & 14 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@
#define WRITE_D64 write_d64_le
#endif

static unsigned char pcm_guid[16] =
{
/* (00000001-0000-0010-8000-00aa00389b71) */

0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
};

static unsigned char ieee_float_guid[16] =
{
/* (00000003-0000-0010-8000-00aa00389b71) */

0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
};

/* Define the supported formats here */
input_format formats[] = {
{wav_id, 12, wav_open, wav_close, "wav", N_("WAV file reader")},
Expand Down Expand Up @@ -587,7 +601,7 @@ int wav_id(unsigned char *buf, int len)

int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
{
unsigned char buf[16];
unsigned char buf[81];
Int64_t len;
Int64_t current_pos;
int samplesize;
Expand All @@ -614,21 +628,20 @@ int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
* in size. This is incorrect, but not fatal, so we only warn about
* it instead of refusing to work with the file. Please, if you
* have a program that's creating format chunks of sizes other than
* 16 or 18 bytes in size, report a bug to the author.
* 16, 18 or 40 bytes in size, report a bug to the author.
* (40 bytes accommodates WAVEFORMATEXTENSIBLE conforming files.)
*/
if (len != 16 && len != 18)
if (len != 16 && len != 18 && len != 40)
fprintf(stderr, "Warning: INVALID format chunk in wav header.\n"
" Trying to read anyway (may not work)...\n");

if (fread(buf, 1, 16, in) < 16) {
fprintf(stderr, "Warning: Unexpected EOF in reading WAV header (2)\n");
return 0;
}

/* Deal with stupid broken apps. Don't use these programs.
*/
if (len - 16 > 0 && !seek_forward(in, len - 16))
return 0;

if (fread(buf,1,len,in) < len) {
fprintf(stderr, "Warning: Unexpected EOF in reading WAV header\n");
return 0;
}

format.format = READ_U16_LE(buf);
format.channels = READ_U16_LE(buf+2);
Expand Down Expand Up @@ -667,26 +680,58 @@ int wav_open(FILE *in, wavegain_opt *opt, unsigned char *oldbuf, int buflen)
FSEEK64(in, current_pos, SEEK_SET);
}

if (format.format == 1) {
samplesize = format.samplesize / 8;
if(format.format == WAVE_FORMAT_PCM) {
samplesize = format.samplesize/8;
opt->read_samples = wav_read;
/* works with current enum */
opt->format = samplesize;
}
else if (format.format == 3) {
else if(format.format == WAVE_FORMAT_IEEE_FLOAT) {
samplesize = 4;
opt->read_samples = wav_ieee_read;
opt->endianness = LITTLE;
opt->format = WAV_FMT_FLOAT;
}
else if (format.format == WAVE_FORMAT_EXTENSIBLE) {
format.channel_mask = READ_U32_LE(buf+20);
if (format.channel_mask != SPEAKER_FRONT_LEFT || format.channel_mask != (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)) {
fprintf(stderr, "ERROR: Wav file is unsupported type (must be standard 1 or 2 channel PCM\n"
" or type 3 floating point PCM)(2)\n");
return 0;
}
if (memcmp(buf+24, pcm_guid, 16) == 0) {
samplesize = format.samplesize/8;
opt->read_samples = wav_read;
/* works with current enum */
opt->format = samplesize;
}
else if (memcmp(buf+24, ieee_float_guid, 16) == 0) {
samplesize = 4;
opt->read_samples = wav_ieee_read;
opt->endianness = LITTLE;
opt->format = WAV_FMT_FLOAT;
}
else {
fprintf(stderr, "ERROR: Wav file is unsupported type (must be standard PCM\n"
" or type 3 floating point PCM)(2)\n");
return 0;
}
}
else {
fprintf(stderr, "ERROR: Wav file is unsupported type (must be standard PCM\n"
" or type 3 floating point PCM)\n");
" or type 3 floating point PCM\n");
return 0;
}

opt->samplesize = format.samplesize;

if(format.align != format.channels * samplesize) {
/* This is incorrect according to the spec. Warn loudly, then ignore
* this value.
*/
fprintf(stderr, _("Warning: WAV 'block alignment' value is incorrect, ignoring.\n"
"The software that created this file is incorrect.\n"));
}
if ( format.align == format.channels * samplesize &&
format.samplesize == samplesize * 8 &&
(format.samplesize == 32 || format.samplesize == 24 ||
Expand Down
30 changes: 24 additions & 6 deletions audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ extern "C" {
#include <stdio.h>
#include "misc.h"

/* In WIN32, the following bitmap can be found in sdk\inc\ksmedia.h and sdk\inc\mmreg.h: */

#ifndef SPEAKER_FRONT_LEFT
# define SPEAKER_FRONT_LEFT 0x1
# define SPEAKER_FRONT_RIGHT 0x2
#endif

#ifndef WAVE_FORMAT_PCM
# define WAVE_FORMAT_PCM 0x0001
#endif
#ifndef WAVE_FORMAT_IEEE_FLOAT
# define WAVE_FORMAT_IEEE_FLOAT 0x0003
#endif
#ifndef WAVE_FORMAT_EXTENSIBLE
# define WAVE_FORMAT_EXTENSIBLE 0xfffe
#endif

typedef long (*audio_read_func)(void *src,
double **buffer,
int samples,
Expand Down Expand Up @@ -77,12 +94,13 @@ typedef struct


typedef struct {
short format;
short channels;
int samplerate;
int bytespersec;
short align;
short samplesize;
unsigned short format;
unsigned short channels;
unsigned int channel_mask;
unsigned int samplerate;
unsigned int bytespersec;
unsigned short align;
unsigned short samplesize;
} wav_fmt;

typedef struct {
Expand Down
Loading

0 comments on commit bff3cf0

Please sign in to comment.