just upload everything
This commit is contained in:
parent
ce63949d29
commit
f4bb23ad1e
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
nanoquake.h -- common quake engine defintions as single-header library
|
||||
Copyright (C) 1997 id Software
|
||||
Copyright (C) 2024 Uncle Mike, Alibek Omarov
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
#ifndef NANOQUAKE_H
|
||||
#define NANOQUAKE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef NANOQUAKE_IMPL
|
||||
#define EXTERN
|
||||
#else // NANOQUAKE_IMPL
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#define Assert assert
|
||||
|
||||
//
|
||||
// mathlib
|
||||
//
|
||||
#define Q_min( x, y ) (( x ) < ( y ) ? ( x ) : ( y ))
|
||||
#define Q_max( x, y ) (( x ) > ( y ) ? ( x ) : ( y ))
|
||||
#define bound( min, val, max ) Q_min( Q_max( min, val ), max )
|
||||
#define SetBits( x, y ) ((x) |= (y))
|
||||
#define ClearBits( x, y ) ((x) &= ~(y))
|
||||
#define FBitSet( x, y ) ((x) & (y))
|
||||
#define ARRAYSIZE( array ) ( sizeof( array ) / sizeof( array[0] ))
|
||||
|
||||
//
|
||||
// common
|
||||
//
|
||||
#ifndef __cplusplus
|
||||
typedef enum { false, true } qboolean;
|
||||
#else
|
||||
typedef int qboolean;
|
||||
#endif
|
||||
typedef unsigned char byte;
|
||||
typedef off_t fs_offset_t;
|
||||
#define Z_Free free
|
||||
#define Z_Calloc( x ) calloc( 1, x )
|
||||
#define Mem_Malloc( x, y ) malloc( y )
|
||||
#define Con_Printf printf
|
||||
#define Con_DPrintf printf
|
||||
#define Con_Reportf printf
|
||||
#define Q_atof atof
|
||||
#define Q_atoi atoi
|
||||
#define COM_RandomLong( min, max ) ( min + rand() % ( max - min ))
|
||||
#define Q_strncmp strncmp
|
||||
#define S_NOTE "Note: "
|
||||
#define S_WARN "Warning: "
|
||||
#define S_ERROR "Error: "
|
||||
|
||||
//
|
||||
// cvars
|
||||
//
|
||||
|
||||
typedef struct cvar_s
|
||||
{
|
||||
const char *name;
|
||||
char *string;
|
||||
int flags;
|
||||
float value;
|
||||
struct cvar_s *next;
|
||||
} cvar_t;
|
||||
|
||||
#define CVAR_SENTINEL 0xdeadbeef
|
||||
|
||||
#define CVAR_DEFINE( cv, cvname, cvstr, cvflags, cvdesc ) \
|
||||
cvar_t cv = { (char*)cvname, (char*)cvstr, cvflags, 0.0f, (void *)CVAR_SENTINEL }
|
||||
|
||||
#define CVAR_DEFINE_AUTO( cv, cvstr, cvflags, cvdesc ) \
|
||||
CVAR_DEFINE( cv, #cv, cvstr, cvflags, cvdesc )
|
||||
|
||||
#define FCVAR_ARCHIVE (1 << 0)
|
||||
#define FCVAR_CHANGED (1 << 13)
|
||||
|
||||
static inline void Cvar_DirectSet( cvar_t *cv, const char *value )
|
||||
{
|
||||
free( cv->string );
|
||||
cv->string = strdup( value );
|
||||
cv->value = atoi( cv->string );
|
||||
cv->flags |= FCVAR_CHANGED;
|
||||
}
|
||||
|
||||
static inline void Cvar_DirectSetValue( cvar_t *cv, float value )
|
||||
{
|
||||
char str[32];
|
||||
|
||||
snprintf( str, sizeof( str ), "%f", value );
|
||||
|
||||
free( cv->string );
|
||||
cv->string = strdup( str );
|
||||
cv->value = value;
|
||||
cv->flags |= FCVAR_CHANGED;
|
||||
}
|
||||
|
||||
static inline void Cvar_RegisterVariable( cvar_t *cv )
|
||||
{
|
||||
cv->string = strdup( cv->string );
|
||||
cv->value = atoi( cv->string );
|
||||
}
|
||||
|
||||
//
|
||||
// cmds
|
||||
//
|
||||
#define Cmd_Argc() cmd_argc
|
||||
#define Cmd_Argv( i ) cmd_argv[i]
|
||||
|
||||
EXTERN int cmd_argc;
|
||||
EXTERN char **cmd_argv;
|
||||
|
||||
static inline void Cmd_ExecCommand( void (*func)(), int argc, char **argv )
|
||||
{
|
||||
cmd_argc = argc;
|
||||
cmd_argv = argv;
|
||||
func();
|
||||
}
|
||||
|
||||
static inline void Cmd_AddCommand( const char *cmd, void *func, const char *desc )
|
||||
{
|
||||
}
|
||||
static inline void Cmd_RemoveCommand( const char *cmd )
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// time
|
||||
//
|
||||
static inline double Sys_DoubleTime( void )
|
||||
{
|
||||
struct timespec ts;
|
||||
#if __irix__
|
||||
clock_gettime( CLOCK_SGI_CYCLE, &ts );
|
||||
#else
|
||||
clock_gettime( CLOCK_MONOTONIC, &ts );
|
||||
#endif
|
||||
return (double) ts.tv_sec + (double) ts.tv_nsec/1000000000.0;
|
||||
}
|
||||
|
||||
//
|
||||
// sound
|
||||
//
|
||||
#define SOUND_11k (11025)
|
||||
#define CLIP( x ) (( x ) > 32760 ? 32760 : (( x ) < -32760 ? -32760 : ( x )))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int left;
|
||||
int right;
|
||||
} portable_samplepair_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int waterlevel;
|
||||
} listener_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WF_UNKNOWN = 0,
|
||||
WF_PCMDATA,
|
||||
WF_MPGDATA,
|
||||
WF_TOTALCOUNT, // must be last
|
||||
} sndformat_t;
|
||||
|
||||
typedef struct sndlib_s
|
||||
{
|
||||
// current sound state
|
||||
int type; // sound type
|
||||
int rate; // num samples per second (e.g. 11025 - 11 khz)
|
||||
int width; // resolution - bum bits divided by 8 (8 bit is 1, 16 bit is 2)
|
||||
int channels; // num channels (1 - mono, 2 - stereo)
|
||||
int loopstart; // start looping from
|
||||
uint samples; // total samplecount in sound
|
||||
uint flags; // additional sound flags
|
||||
size_t size; // sound unpacked size (for bounds checking)
|
||||
byte *wav; // sound pointer (see sound_type for details)
|
||||
|
||||
byte *tempbuffer; // for convert operations
|
||||
int cmd_flags;
|
||||
} sndlib_t;
|
||||
|
||||
EXTERN sndlib_t sound;
|
||||
EXTERN listener_t s_listener;
|
||||
|
||||
qboolean Sound_LoadWAV( const char *name, const byte *buffer, fs_offset_t filesize );
|
||||
|
||||
#endif // NANOQUAKE_H
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
gcc *.c -I. -O3 -o hldsp
|
||||
wget -O temp.opus $1 # not really opus of course
|
||||
ffmpeg -i temp.opus -ar 22050 temp.wav
|
||||
./hldsp $2 temp.wav out.wav
|
||||
ffmpeg -i out.wav out.opus
|
||||
|
||||
rm temp.wav out.wav temp.opus
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
gcc *.c -I. -O3 -o hldsp
|
||||
yt-dlp --extract-audio $1 --audio-format opus -o temp.opus
|
||||
ffmpeg -i temp.opus -ar 22050 temp.wav
|
||||
./hldsp $2 temp.wav out.wav
|
||||
ffmpeg -i out.wav out.opus
|
||||
|
||||
rm temp.wav out.wav temp.opus
|
|
@ -0,0 +1,255 @@
|
|||
/*
|
||||
snd_wav.c - wav format load & save
|
||||
Copyright (C) 2010 Uncle Mike
|
||||
Copyright (C) 2023 FTEQW developers
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "nanoquake.h"
|
||||
|
||||
static const byte *iff_data;
|
||||
static const byte *iff_dataPtr;
|
||||
static const byte *iff_end;
|
||||
static const byte *iff_lastChunk;
|
||||
static int iff_chunkLen;
|
||||
|
||||
/*
|
||||
=================
|
||||
GetLittleShort
|
||||
=================
|
||||
*/
|
||||
static short GetLittleShort( void )
|
||||
{
|
||||
short val = 0;
|
||||
|
||||
val += (*(iff_dataPtr+0) << 0);
|
||||
val += (*(iff_dataPtr+1) << 8);
|
||||
iff_dataPtr += 2;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
GetLittleLong
|
||||
=================
|
||||
*/
|
||||
static int GetLittleLong( void )
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
val += (*(iff_dataPtr+0) << 0);
|
||||
val += (*(iff_dataPtr+1) << 8);
|
||||
val += (*(iff_dataPtr+2) <<16);
|
||||
val += (*(iff_dataPtr+3) <<24);
|
||||
iff_dataPtr += 4;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
FindNextChunk
|
||||
=================
|
||||
*/
|
||||
static void FindNextChunk( const char *filename, const char *name )
|
||||
{
|
||||
while( 1 )
|
||||
{
|
||||
ptrdiff_t remaining = iff_end - iff_lastChunk;
|
||||
|
||||
if( remaining < 8 )
|
||||
{
|
||||
iff_dataPtr = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
iff_dataPtr = iff_lastChunk + 4;
|
||||
remaining -= 8;
|
||||
|
||||
iff_chunkLen = GetLittleLong();
|
||||
if( iff_chunkLen < 0 )
|
||||
{
|
||||
iff_dataPtr = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if( iff_chunkLen > remaining )
|
||||
{
|
||||
Con_DPrintf( "%s: '%s' truncated by %i bytes\n", __func__, filename, iff_chunkLen - remaining );
|
||||
iff_chunkLen = remaining;
|
||||
}
|
||||
|
||||
remaining -= iff_chunkLen;
|
||||
iff_dataPtr -= 8;
|
||||
|
||||
iff_lastChunk = iff_dataPtr + 8 + iff_chunkLen;
|
||||
if ((iff_chunkLen&1) && remaining)
|
||||
iff_lastChunk++;
|
||||
if (!Q_strncmp(iff_dataPtr, name, 4))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
FindChunk
|
||||
=================
|
||||
*/
|
||||
static void FindChunk( const char *filename, const char *name )
|
||||
{
|
||||
iff_lastChunk = iff_data;
|
||||
FindNextChunk( filename, name );
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
Sound_LoadWAV
|
||||
=============
|
||||
*/
|
||||
qboolean Sound_LoadWAV( const char *name, const byte *buffer, fs_offset_t filesize )
|
||||
{
|
||||
int samples, fmt;
|
||||
|
||||
if( !buffer || filesize <= 0 )
|
||||
return false;
|
||||
|
||||
iff_data = buffer;
|
||||
iff_end = buffer + filesize;
|
||||
|
||||
// find "RIFF" chunk
|
||||
FindChunk( name, "RIFF" );
|
||||
|
||||
if( !( iff_dataPtr && !Q_strncmp( (const char *)iff_dataPtr + 8, "WAVE", 4 )))
|
||||
{
|
||||
Con_DPrintf( S_ERROR "Sound_LoadWAV: %s missing 'RIFF/WAVE' chunks\n", name );
|
||||
return false;
|
||||
}
|
||||
|
||||
// get "fmt " chunk
|
||||
iff_data = iff_dataPtr + 12;
|
||||
FindChunk( name, "fmt " );
|
||||
|
||||
if( !iff_dataPtr )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "Sound_LoadWAV: %s missing 'fmt ' chunk\n", name );
|
||||
return false;
|
||||
}
|
||||
|
||||
iff_dataPtr += 8;
|
||||
fmt = GetLittleShort();
|
||||
|
||||
if( fmt != 1 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "Sound_LoadWAV: %s not a microsoft PCM format\n", name );
|
||||
return false;
|
||||
}
|
||||
|
||||
sound.channels = GetLittleShort();
|
||||
if( sound.channels != 1 && sound.channels != 2 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "Sound_LoadWAV: only mono and stereo WAV files supported (%s)\n", name );
|
||||
return false;
|
||||
}
|
||||
|
||||
sound.rate = GetLittleLong();
|
||||
iff_dataPtr += 6;
|
||||
|
||||
sound.width = GetLittleShort() / 8;
|
||||
|
||||
if( sound.width != 1 && sound.width != 2 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "Sound_LoadWAV: only 8 and 16 bit WAV files supported (%s)\n", name );
|
||||
return false;
|
||||
}
|
||||
|
||||
// get cue chunk
|
||||
FindChunk( name, "cue " );
|
||||
|
||||
if( iff_dataPtr )
|
||||
{
|
||||
iff_dataPtr += 32;
|
||||
sound.loopstart = GetLittleLong();
|
||||
FindNextChunk( name, "LIST" ); // if the next chunk is a LIST chunk, look for a cue length marker
|
||||
|
||||
if( iff_dataPtr )
|
||||
{
|
||||
if( !Q_strncmp( (const char *)iff_dataPtr + 28, "mark", 4 ))
|
||||
{
|
||||
// this is not a proper parse, but it works with CoolEdit...
|
||||
iff_dataPtr += 24;
|
||||
sound.samples = sound.loopstart + GetLittleLong(); // samples in loop
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sound.loopstart = -1;
|
||||
sound.samples = 0;
|
||||
}
|
||||
|
||||
// find data chunk
|
||||
FindChunk( name, "data" );
|
||||
|
||||
if( !iff_dataPtr )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "Sound_LoadWAV: %s missing 'data' chunk\n", name );
|
||||
return false;
|
||||
}
|
||||
|
||||
iff_dataPtr += 4;
|
||||
samples = GetLittleLong() / sound.width;
|
||||
|
||||
if( sound.samples )
|
||||
{
|
||||
if( samples < sound.samples )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "Sound_LoadWAV: %s has a bad loop length\n", name );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else sound.samples = samples;
|
||||
|
||||
if( sound.samples <= 0 )
|
||||
{
|
||||
Con_Reportf( S_ERROR "Sound_LoadWAV: file with %i samples (%s)\n", sound.samples, name );
|
||||
return false;
|
||||
}
|
||||
|
||||
sound.type = WF_PCMDATA;
|
||||
sound.samples /= sound.channels;
|
||||
|
||||
// Load the data
|
||||
sound.size = sound.samples * sound.width * sound.channels;
|
||||
sound.wav = Mem_Malloc( host.soundpool, sound.size );
|
||||
|
||||
memcpy( sound.wav, buffer + (iff_dataPtr - buffer), sound.size );
|
||||
|
||||
// now convert 8-bit sounds to signed
|
||||
if( sound.width == 1 )
|
||||
{
|
||||
int i, j;
|
||||
signed char *pData = (signed char *)sound.wav;
|
||||
|
||||
for( i = 0; i < sound.samples; i++ )
|
||||
{
|
||||
for( j = 0; j < sound.channels; j++ )
|
||||
{
|
||||
*pData = (byte)((int)((byte)*pData) - 128 );
|
||||
pData++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue