mirror of
https://github.com/nillerusr/source-engine.git
synced 2024-12-22 14:16:50 +00:00
add mp3 codecs(broken)
This commit is contained in:
parent
db42098a5a
commit
235b52db3f
@ -668,7 +668,7 @@ void VAudioInit()
|
||||
g_pFileSystem->GetLocalCopy( "mss32.dll" );
|
||||
}
|
||||
|
||||
g_pVAudioModule = FileSystem_LoadModule( "vaudio_miles" );
|
||||
g_pVAudioModule = FileSystem_LoadModule( "vaudio_minimp3" );
|
||||
if ( g_pVAudioModule )
|
||||
{
|
||||
CreateInterfaceFn vaudioFactory = Sys_GetFactory( g_pVAudioModule );
|
||||
|
198
engine/voice_codecs/minimp3/mp3codecs.cpp
Normal file
198
engine/voice_codecs/minimp3/mp3codecs.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
#include "interface.h"
|
||||
|
||||
#define MINIMP3_IMPLEMENTATION
|
||||
#include "minimp3_ex.h"
|
||||
#include "vaudio/ivaudio.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
struct AudioStream_s
|
||||
{
|
||||
IAudioStreamEvent *stream_event;
|
||||
int offset;
|
||||
unsigned int decode_size;
|
||||
};
|
||||
|
||||
size_t mp3dec_read_callback(void *buf, size_t size, void *user_data)
|
||||
{
|
||||
AudioStream_s *stream = static_cast<AudioStream_s*>( (void*)user_data);
|
||||
|
||||
if( stream->decode_size > 0)
|
||||
{
|
||||
printf("mp3dec_read_callback size: %d\n", (int)size);
|
||||
return size;
|
||||
}
|
||||
|
||||
int ret_size = stream->stream_event->StreamRequestData( buf, size, stream->offset );
|
||||
printf("mp3dec_read_callback size: %d, ret_size: %d\n", (int)size, ret_size);
|
||||
stream->offset += ret_size;
|
||||
|
||||
return ret_size;
|
||||
}
|
||||
|
||||
|
||||
int mp3dec_seek_callback(uint64_t position, void *user_data)
|
||||
{
|
||||
struct AudioStream_s *stream = static_cast<AudioStream_s*>( (void*)user_data);
|
||||
stream->offset = position;
|
||||
printf("mp3dec_seek_callback position: %d\n", (int)position);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
class CMiniMP3 : public IAudioStream
|
||||
{
|
||||
public:
|
||||
CMiniMP3();
|
||||
bool Init( IAudioStreamEvent *pHandler );
|
||||
~CMiniMP3();
|
||||
|
||||
// IAudioStream functions
|
||||
virtual int Decode( void *pBuffer, unsigned int bufferSize );
|
||||
virtual int GetOutputBits();
|
||||
virtual int GetOutputRate();
|
||||
virtual int GetOutputChannels();
|
||||
virtual unsigned int GetPosition();
|
||||
virtual void SetPosition( unsigned int position );
|
||||
private:
|
||||
|
||||
short pcm[MINIMP3_MAX_SAMPLES_PER_FRAME];
|
||||
mp3dec_ex_t mp3d;
|
||||
mp3dec_io_t mp3io;
|
||||
struct AudioStream_s audio_stream;
|
||||
};
|
||||
|
||||
CMiniMP3::CMiniMP3()
|
||||
{
|
||||
}
|
||||
|
||||
bool CMiniMP3::Init( IAudioStreamEvent *pHandler )
|
||||
{
|
||||
printf("CMiniMP3::Init\n");
|
||||
|
||||
audio_stream.stream_event = pHandler;
|
||||
audio_stream.offset = 0;
|
||||
audio_stream.decode_size = 0;
|
||||
|
||||
mp3io.read = &mp3dec_read_callback;
|
||||
mp3io.read_data = &audio_stream;
|
||||
mp3io.seek = &mp3dec_seek_callback;
|
||||
mp3io.seek_data = &audio_stream;
|
||||
if( mp3dec_ex_open_cb(&mp3d, &mp3io, MP3D_SEEK_TO_SAMPLE) )
|
||||
{
|
||||
printf("mp3dec_ex_open_cb failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( mp3dec_ex_seek(&mp3d, 0) )
|
||||
{
|
||||
printf("mp3dec_ex_seek failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CMiniMP3::~CMiniMP3()
|
||||
{
|
||||
// m_decoder.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
// IAudioStream functions
|
||||
int CMiniMP3::Decode( void *pBuffer, unsigned int bufferSize )
|
||||
{
|
||||
printf("CMiniMP3::Decode size: %d\n", bufferSize);
|
||||
audio_stream.decode_size = 1;
|
||||
unsigned int readed = mp3dec_ex_read(&mp3d, (mp3d_sample_t*)pBuffer, bufferSize/2);
|
||||
printf("mp3dec_ex_read %d\n", readed);
|
||||
printf("dec.samples: %d\n", (int)mp3d.samples);
|
||||
|
||||
if (readed != mp3d.samples) /* normal eof or error condition */
|
||||
{
|
||||
if (mp3d.last_error)
|
||||
{
|
||||
printf("last_err: %d\n", mp3d.last_error);
|
||||
/* error */
|
||||
}
|
||||
}
|
||||
|
||||
return readed;
|
||||
}
|
||||
|
||||
|
||||
int CMiniMP3::GetOutputBits()
|
||||
{
|
||||
printf("CMiniMP3::GetOutputBits\n");
|
||||
return 16;
|
||||
// return m_decoder.GetAttribute( m_decoder.OUTPUT_BITS );
|
||||
}
|
||||
|
||||
|
||||
int CMiniMP3::GetOutputRate()
|
||||
{
|
||||
printf("CMiniMP3::GetOutputRate: %d\n", 44100);
|
||||
return 44100;
|
||||
// return m_decoder.GetAttribute( m_decoder.OUTPUT_RATE );
|
||||
}
|
||||
|
||||
|
||||
int CMiniMP3::GetOutputChannels()
|
||||
{
|
||||
printf("CMiniMP3::GetOutputChannels %d\n", 2);
|
||||
return 2;
|
||||
// return m_decoder.GetAttribute( m_decoder.OUTPUT_CHANNELS );
|
||||
}
|
||||
|
||||
|
||||
unsigned int CMiniMP3::GetPosition()
|
||||
{
|
||||
printf("CMiniMP3::GetPosition %d\n", 0);
|
||||
return 0;
|
||||
// return m_decoder.GetAttribute( m_decoder.POSITION );
|
||||
}
|
||||
|
||||
// NOTE: Only supports seeking forward right now
|
||||
void CMiniMP3::SetPosition( unsigned int position )
|
||||
{
|
||||
printf("CMiniMP3::SetPosition %d\n", position);
|
||||
// m_decoder.Seek( position );
|
||||
}
|
||||
|
||||
|
||||
class CVAudio : public IVAudio
|
||||
{
|
||||
public:
|
||||
CVAudio()
|
||||
{
|
||||
// Assume the user will be creating multiple miles objects, so
|
||||
// keep miles running while this exists
|
||||
//IncrementRefMiles();
|
||||
}
|
||||
|
||||
~CVAudio()
|
||||
{
|
||||
//DecrementRefMiles();
|
||||
}
|
||||
|
||||
IAudioStream *CreateMP3StreamDecoder( IAudioStreamEvent *pEventHandler )
|
||||
{
|
||||
CMiniMP3 *pMP3 = new CMiniMP3;
|
||||
if ( !pMP3->Init( pEventHandler ) )
|
||||
{
|
||||
delete pMP3;
|
||||
return NULL;
|
||||
}
|
||||
return pMP3;
|
||||
}
|
||||
|
||||
void DestroyMP3StreamDecoder( IAudioStream *pDecoder )
|
||||
{
|
||||
delete pDecoder;
|
||||
}
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE( CVAudio, IVAudio, VAUDIO_INTERFACE_VERSION );
|
||||
|
34
engine/voice_codecs/minimp3/vaudio_minimp3.vpc
Normal file
34
engine/voice_codecs/minimp3/vaudio_minimp3.vpc
Normal file
@ -0,0 +1,34 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// VAUDIO_MINIMP3.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
$Macro SRCDIR "..\..\.."
|
||||
$Macro OUTBINDIR "$LIBPUBLIC"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,$SRCDIR\thirdparty\minimp3\,..\..\..\public,..\..\..\public\tier1,..\..,..\..\..\common,..\..\audio\public"
|
||||
$PreprocessorDefinitions "$BASE;"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "vaudio_minimp3"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "mp3codecs.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\tier1\interface.h"
|
||||
$File "$SRCDIR\public\vaudio\ivaudio.h"
|
||||
}
|
||||
}
|
7
thirdparty/minimp3/.gitignore
vendored
Normal file
7
thirdparty/minimp3/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
fate-suite.ffmpeg.org
|
||||
player/SDL
|
||||
minimp3
|
||||
minimp3_arm
|
||||
*.gcda
|
||||
*.gcno
|
||||
*.gcov
|
34
thirdparty/minimp3/.travis.yml
vendored
Normal file
34
thirdparty/minimp3/.travis.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
dist: bionic
|
||||
language: c
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- build-essential
|
||||
- libc6-dev-i386
|
||||
- linux-libc-dev:i386
|
||||
- gcc-arm-none-eabi
|
||||
- libnewlib-arm-none-eabi
|
||||
- gcc-7-multilib
|
||||
- gcc-7-aarch64-linux-gnu
|
||||
- gcc-7-powerpc-linux-gnu
|
||||
- gcc-aarch64-linux-gnu
|
||||
- gcc-powerpc-linux-gnu
|
||||
- libc6-arm64-cross
|
||||
- libc6-powerpc-cross
|
||||
- libc6-dev-arm64-cross
|
||||
- libc6-dev-powerpc-cross
|
||||
- qemu
|
||||
- lcov
|
||||
|
||||
os:
|
||||
- linux
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
script:
|
||||
- scripts/build.sh
|
||||
- (pushd player/; ./build.sh linux; popd)
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
117
thirdparty/minimp3/LICENSE
vendored
Normal file
117
thirdparty/minimp3/LICENSE
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
CC0 1.0 Universal
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||
subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||
purpose of contributing to a commons of creative, cultural and scientific
|
||||
works ("Commons") that the public can reliably and without fear of later
|
||||
claims of infringement build upon, modify, incorporate in other works, reuse
|
||||
and redistribute as freely as possible in any form whatsoever and for any
|
||||
purposes, including without limitation commercial purposes. These owners may
|
||||
contribute to the Commons to promote the ideal of a free culture and the
|
||||
further production of creative, cultural and scientific works, or to gain
|
||||
reputation or greater distribution for their Work in part through the use and
|
||||
efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any expectation
|
||||
of additional consideration or compensation, the person associating CC0 with a
|
||||
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
||||
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
||||
and publicly distribute the Work under its terms, with knowledge of his or her
|
||||
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||
effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not limited
|
||||
to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
||||
and translate a Work;
|
||||
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
|
||||
iii. publicity and privacy rights pertaining to a person's image or likeness
|
||||
depicted in a Work;
|
||||
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data in
|
||||
a Work;
|
||||
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation thereof,
|
||||
including any amended or successor version of such directive); and
|
||||
|
||||
vii. other similar, equivalent or corresponding rights throughout the world
|
||||
based on applicable law or treaty, and any national implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
||||
and Related Rights and associated claims and causes of action, whether now
|
||||
known or unknown (including existing as well as future claims and causes of
|
||||
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||
duration provided by applicable law or treaty (including future time
|
||||
extensions), (iii) in any current or future medium and for any number of
|
||||
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
||||
the Waiver for the benefit of each member of the public at large and to the
|
||||
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
||||
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||
by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||
shall be preserved to the maximum extent permitted taking into account
|
||||
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
||||
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
||||
non transferable, non sublicensable, non exclusive, irrevocable and
|
||||
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
||||
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
||||
provided by applicable law or treaty (including future time extensions), (iii)
|
||||
in any current or future medium and for any number of copies, and (iv) for any
|
||||
purpose whatsoever, including without limitation commercial, advertising or
|
||||
promotional purposes (the "License"). The License shall be deemed effective as
|
||||
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
||||
License for any reason be judged legally invalid or ineffective under
|
||||
applicable law, such partial invalidity or ineffectiveness shall not
|
||||
invalidate the remainder of the License, and in such case Affirmer hereby
|
||||
affirms that he or she will not (i) exercise any of his or her remaining
|
||||
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
||||
and causes of action with respect to the Work, in either case contrary to
|
||||
Affirmer's express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
|
||||
b. Affirmer offers the Work as-is and makes no representations or warranties
|
||||
of any kind concerning the Work, express, implied, statutory or otherwise,
|
||||
including without limitation warranties of title, merchantability, fitness
|
||||
for a particular purpose, non infringement, or the absence of latent or
|
||||
other defects, accuracy, or the present or absence of errors, whether or not
|
||||
discoverable, all to the greatest extent permissible under applicable law.
|
||||
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without limitation
|
||||
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
||||
disclaims responsibility for obtaining any necessary consents, permissions
|
||||
or other rights required for any use of the Work.
|
||||
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to this
|
||||
CC0 or use of the Work.
|
||||
|
||||
For more information, please see
|
||||
<http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
|
1855
thirdparty/minimp3/minimp3.h
vendored
Normal file
1855
thirdparty/minimp3/minimp3.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1387
thirdparty/minimp3/minimp3_ex.h
vendored
Normal file
1387
thirdparty/minimp3/minimp3_ex.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -196,6 +196,7 @@ $Group "game"
|
||||
|
||||
$Group "everything"
|
||||
{
|
||||
"vaudio_minimp3"
|
||||
"socketlib"
|
||||
"actbusy"
|
||||
"adminserver"
|
||||
|
@ -386,7 +386,7 @@ $Project "haptics"
|
||||
|
||||
$Project "havana_constraints"
|
||||
{
|
||||
// "ivp\havana\havana_constraints.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
"ivp\havana\havana_constraints.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
}
|
||||
|
||||
$Project "height2normal"
|
||||
@ -401,12 +401,12 @@ $Project "height2ssbump"
|
||||
|
||||
$Project "hk_base"
|
||||
{
|
||||
// "ivp\havana\havok\hk_base\hk_base.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
"ivp\havana\havok\hk_base\hk_base.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
}
|
||||
|
||||
$Project "hk_math"
|
||||
{
|
||||
// "ivp\havana\havok\hk_math\hk_math.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
"ivp\havana\havok\hk_math\hk_math.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
}
|
||||
|
||||
// FIXME why doesn't source2 define this?
|
||||
@ -506,7 +506,7 @@ $Project "inputtest"
|
||||
|
||||
$Project "ivp_compactbuilder"
|
||||
{
|
||||
// "ivp\ivp_compact_builder\ivp_compactbuilder.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
"ivp\ivp_compact_builder\ivp_compactbuilder.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
}
|
||||
|
||||
$Project "itemtest_com"
|
||||
@ -526,7 +526,7 @@ $Project "itemtest_lib"
|
||||
|
||||
$Project "ivp_physics"
|
||||
{
|
||||
// "ivp\ivp_physics\ivp_physics.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
"ivp\ivp_physics\ivp_physics.vpc" [$WINDOWS||$X360||$POSIX]
|
||||
}
|
||||
|
||||
$Project "jpeglib"
|
||||
@ -1290,6 +1290,11 @@ $Project "vaudio_miles"
|
||||
// "engine\voice_codecs\miles\vaudio_miles.vpc" [$WINDOWS||$POSIX]
|
||||
}
|
||||
|
||||
$Project "vaudio_minimp3"
|
||||
{
|
||||
"engine\voice_codecs\minimp3\vaudio_minimp3.vpc" [$WINDOWS||$POSIX]
|
||||
}
|
||||
|
||||
$Project "vbsp"
|
||||
{
|
||||
"utils\vbsp\vbsp.vpc" [$WIN32]
|
||||
|
Loading…
Reference in New Issue
Block a user