#include <libsswf.h>
Inheritance diagram for sswf::TagSound:
Public Types | |
SOUND_ENDIAN_BIG | |
The data is in big endian. | |
SOUND_ENDIAN_DONTUSE | |
The data is defined on 8 bits. | |
SOUND_ENDIAN_LITTLE = 0 | |
The data is in little endian. | |
SOUND_ENDIAN_SAME | |
The data is in the same endian. | |
enum | sound_endian_t { SOUND_ENDIAN_LITTLE = 0, SOUND_ENDIAN_BIG, SOUND_ENDIAN_SAME, SOUND_ENDIAN_DONTUSE, SOUND_ENDIAN_UNKNOWN } |
Valid endians for sound samples. More... | |
SOUND_ENDIAN_UNKNOWN | |
The data endianess is not known. | |
SOUND_FORMAT_ADPCM = 1 | |
This format is used to save compressed sound data using the ADPCM format. | |
SOUND_FORMAT_MP3 = 2 | |
This format is used to save compressed music data using the MP3 format. | |
SOUND_FORMAT_NELLYMOSER = 6 | |
This format is used to save compressed voice with high quality. | |
SOUND_FORMAT_RAW = 0 | |
This format is used to save uncompressed sound data. | |
enum | sound_format_t { SOUND_FORMAT_UNKNOWN = -1, SOUND_FORMAT_RAW = 0, SOUND_FORMAT_ADPCM = 1, SOUND_FORMAT_MP3 = 2, SOUND_FORMAT_UNCOMPRESSED = 3, SOUND_FORMAT_NELLYMOSER = 6 } |
Valid formats of sounds in Flash. More... | |
SOUND_FORMAT_UNCOMPRESSED = 3 | |
This format is used to save small uncompressed sound effect with full quality. | |
SOUND_FORMAT_UNKNOWN = -1 | |
An undefined or unknown format. | |
Public Member Functions | |
size_t | GetSamplesCount (void) const |
Returns the number of samples in that TagSound. | |
virtual ErrorManager::error_code_t | Save (Data &data) |
Save the TagSound in the specified Data buffer. | |
void | Set8Bits (void) |
Force the samples to 8 bits. | |
int | SetData (const void *data, size_t size, sound_endian_t endian, int width, unsigned int rate, bool stereo) |
Set sample data in a TagSound object. | |
ErrorManager::error_code_t | SetFilename (const char *filename) |
Set the name of a sound file. | |
void | SetFormat (sound_format_t format) |
Change the format of the tag. | |
void | SetMono (void) |
Change the current samples to mono. | |
TagSound (TagBase *parent) | |
Initialize a sound tag. | |
virtual swf_type_t | TypeFlags (void) const |
Returns the type of this tag: Define with an ID. | |
Static Public Attributes | |
static const int | g_sound_rates [4] = { 5512, 11025, 22050, 44100 } |
The few valid sound rates supported by Flash. | |
Private Member Functions | |
int | CheckMP3Header (FILE *f, unsigned char *header, int &frame_size) |
Internal function to test the validity of an MP3 header. | |
int | LoadMP3File (FILE *f) |
Load an MP3 sound file. | |
int | LoadWaveFile (FILE *f) |
Load a RIFF or WAVE sound file. | |
virtual ErrorManager::error_code_t | PreSave (void) |
Check that the sound can be saved the way it is. | |
int | ReadMP3Header (FILE *f, unsigned char *header) |
Internal function used to read an MP3 header. | |
short | ReadSample (const unsigned char *data, unsigned short adjust, int in_fmt) |
Change the format of the tag. | |
void | Resample (unsigned char *snd, unsigned int out_bytes, const unsigned char *src, size_t size, unsigned int in_bytes, size_t max, double fix, unsigned short adjust, int in_fmt) |
Function used to resample a set of samples from some format to another. | |
Private Attributes | |
unsigned char * | f_data |
int | f_data_maxsize |
int | f_data_size |
sound_format_t | f_format |
int | f_latency_seek |
int | f_rate |
size_t | f_samples |
bool | f_stereo |
int | f_width |
Static Private Attributes | |
static const int | g_bitrates [2][16] |
used by the MP3 loader | |
static const int | g_frequencies [4][4] |
used by the MP3 loader | |
Classes | |
struct | sound_wave_t |
defines an MP3 sound wave (format, channels, rate, alignment, etc.) More... |
This type lists all the endians supported by the sswf library.
This type lists all the formats supported by the Flash players.
SOUND_FORMAT_UNKNOWN |
An undefined or unknown format.
By default a sound tag is defined as having an unknown format. It is not valid to call SetData() with this value.
|
SOUND_FORMAT_RAW |
This format is used to save uncompressed sound data.
Most of the time, sound samples will be compressed to save space. Very small sounds may be saved in an uncompressed format for better quality. This format should not be used with 16 bits data since it is not possible to know for sure whether the sound effects are in little or big endian (it is dependent on the machine on which you created the Flash animation!)
|
SOUND_FORMAT_ADPCM |
This format is used to save compressed sound data using the ADPCM format.
This is a simple compression scheme somewhat similar in concept to the RLE for images. This is better suited for sound samples of effects than for songs.
|
SOUND_FORMAT_MP3 |
This format is used to save compressed music data using the MP3 format.
This is a complex compression scheme somewhat similar in concept to JPEG for images. This is better suited for sound samples of musics than for talk or effects.
|
SOUND_FORMAT_UNCOMPRESSED |
This format is used to save small uncompressed sound effect with full quality.
This is the uncompressed format to use with uncompressed data. This format ensures the endianess of the data is known (i.e. little endian.) This can be created and played on any system with no problem.
|
SOUND_FORMAT_NELLYMOSER |
This format is used to save compressed voice with high quality.
This is the compressed format to use with voices (with no music in the background). Though MP3 can also be used for voices, you general get a better result with this compression scheme for voices.
|
TagSound::TagSound | ( | TagBase * | parent | ) |
This constructor initializes the sound as empty.
[in] | parent | The TagHeader where this sound is added |
int TagSound::CheckMP3Header | ( | FILE * | f, | |
unsigned char * | header, | |||
int & | frame_size | |||
) | [private] |
This function checks the validity of an MP3 header.
[in] | f | The file descriptor of the MP3 file to check |
[in] | header | A pointer to the header buffer |
[out] | frame_size | Set to the frame size |
size_t TagSound::GetSamplesCount | ( | void | ) | const |
This function returns the current number of samples defined in this TagSound.
int TagSound::LoadMP3File | ( | FILE * | f | ) | [private] |
This function is called with a file descriptor to read a file which is expected to be an MP3 file. If the file cannot be read properly, the function returns with an error (-1).
[in] | f | The file descriptor |
int TagSound::LoadWaveFile | ( | FILE * | f | ) | [private] |
This function is called with a file descriptor to read a file which is expected to be a RIFF or WAVE file. If the file cannot be read properly, the function returns with an error (-1).
[in] | f | The file descriptor |
ErrorManager::error_code_t TagSound::PreSave | ( | void | ) | [private, virtual] |
This function checks that the sound can properly be saved.
This means that all the parameters such as the width, format, stereo, etc. all are acceptable.
Reimplemented from sswf::TagBase.
int TagSound::ReadMP3Header | ( | FILE * | f, | |
unsigned char * | header | |||
) | [private] |
This function reads one MP3 header.
short TagSound::ReadSample | ( | const unsigned char * | data, | |
unsigned short | adjust, | |||
int | in_fmt | |||
) | [private] |
This function reads one sample from a buffer expected to be of format in_fmt and adjusts it as required.
The function is used to resample input samples to samples valid for the specified mode (rate, format, mono or stereo, etc.)
[in] | data | The buffer to read from |
[in] | adjust | The adjustment to make to the input value unsigned |
[in] | in_fmt | The format of the input data |
void TagSound::Resample | ( | unsigned char * | snd, | |
unsigned int | out_bytes, | |||
const unsigned char * | src, | |||
size_t | size, | |||
unsigned int | in_bytes, | |||
size_t | max, | |||
double | fix, | |||
unsigned short | adjust, | |||
int | in_fmt | |||
) | [private] |
This function is used whenever the SetData() or similar function is called with data in a format which is not directly supported by Flash. Then it is resampled to a way that works in Flash.
This means duplicating or removing some of the input samples. When removing samples, an average of a certain number of samples will be computed. This is not always the proper method, but in most cases it works well.
[in] | snd | The destination buffer |
[in] | out_bytes | Size of one sample in the destination buffer (snd + out_bytes moves the pointer to the 2nd sample) |
[in] | src | The source buffer |
[in] | size | The size of the source buffer in bytes |
[in] | in_bytes | Size of one sample in the source buffer (src + in_bytes moves the pointer to the 2nd sample) |
[in] | max | The maximum number of samples to work on (i.e. size of the destination buffer) |
[in] | fix | How much the samples need to be fixed to adjust for the rate difference |
[in] | adjust | The adjustment to make the input value unsigned |
[in] | in_fmt | The format of the samples in the input buffer |
ErrorManager::error_code_t TagSound::Save | ( | Data & | data | ) | [virtual] |
This function saves the sound samples in the specified Data buffer.
[in,out] | data | The data buffer where the tag is saved |
Implements sswf::TagBase.
void TagSound::Set8Bits | ( | void | ) |
This function transforms the current samples from 16 to 8 bits. If the samples already are set at 8 bits, then nothing happens.
This function does not try to adjust the sound, it simply drops the lower 8 bits of each sample.
int TagSound::SetData | ( | const void * | data, | |
size_t | size, | |||
sound_endian_t | endian, | |||
int | width, | |||
unsigned int | rate, | |||
bool | stereo | |||
) |
This function sets the specified user defined data in the TagSound object.
The data is expected to be valid sound samples.
The source samples must be mono or stereo, on 8, 16, 24 or 32 bits, at a reasonable rate (1024 to 88000), in little or big endian.
If the input data has samples which are signed (i.e. -128 to +127 or -32768 to +32767,) then the width must be passed negative (i.e. -8, -16, -24 or -32). Positive values indicate that the input samples are unsigned (i.e. 0 to 255 or 0 to 65535.)
Flash understands only a very limited set of rates:
Note that Flash only understands 8 or 16 bits data. The low bits of 24 and 32 bits samples are dropped.
Stereo samples are expected to be interleaved with the left side sample first.
[in] | data | The source data samples |
[in] | size | The number of bytes in the source buffer (should be a proper multiple) |
[in] | endian | One of the sound endian (little, big, same or unused) |
[in] | width | 8, 16, 24 or 32; or negative to indicate signed data |
[in] | rate | Any rate between 1024 and 88000 inclusive |
[in] | stereo | Whether mono (false) or stereo (true) samples are passed |
ErrorManager::error_code_t TagSound::SetFilename | ( | const char * | filename | ) |
This function takes the name of a file representing a sound effect. The file is loaded on the spot and its content is kept in memory.
This function calls the LoadWaveFile() with a handle to the file it just opened. If that function fails to read the file, then this function tries again by calling the LoadMP3File().
[in] | filename | The name of the file to load |
void TagSound::SetFormat | ( | sound_format_t | format | ) |
This function changes the format of the samples.
[in] | format | The new format. |
void TagSound::SetMono | ( | void | ) |
Force the samples to be mono. The average of the left and right samples is computed.
TagBase::swf_type_t TagSound::TypeFlags | ( | void | ) | const [virtual] |
The TagSound is a definition tag with an identifier
Implements sswf::TagBase.
unsigned char* sswf::TagSound::f_data [private] |
int sswf::TagSound::f_data_maxsize [private] |
int sswf::TagSound::f_data_size [private] |
sound_format_t sswf::TagSound::f_format [private] |
int sswf::TagSound::f_latency_seek [private] |
int sswf::TagSound::f_rate [private] |
size_t sswf::TagSound::f_samples [private] |
bool sswf::TagSound::f_stereo [private] |
int sswf::TagSound::f_width [private] |
const int TagSound::g_bitrates [static, private] |
Initial value:
{ { -1, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1 }, { -1, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1 } }
const int TagSound::g_frequencies [static, private] |
Initial value:
{ { 11025, -1, -1, -1 }, { -1, -1, -1, -1 }, { 22050, -1, -1, -1 }, { 44100, -1, -1, -1 } }
const int TagSound::g_sound_rates = { 5512, 11025, 22050, 44100 } [static] |
Sound effects in Flash only support these rates.
Using an encoding like MP3 can be used to specify different rates in different packets. This is properly supported by newer Flash versions (version 7+)
If possible, you should use one of these rates whenever you call the SetData() function.