partial SoundFile implementation
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5797 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+150
-77
@@ -3,6 +3,8 @@
|
|||||||
* FILE: SoundFile.cpp
|
* FILE: SoundFile.cpp
|
||||||
* DESCR:
|
* DESCR:
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
#include <MediaFile.h>
|
||||||
|
#include <MediaTrack.h>
|
||||||
#include <SoundFile.h>
|
#include <SoundFile.h>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@@ -12,29 +14,31 @@
|
|||||||
|
|
||||||
BSoundFile::BSoundFile()
|
BSoundFile::BSoundFile()
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
_init_raw_stats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BSoundFile::BSoundFile(const entry_ref *ref,
|
BSoundFile::BSoundFile(const entry_ref *ref,
|
||||||
uint32 open_mode)
|
uint32 open_mode)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
_init_raw_stats();
|
||||||
|
SetTo(ref,open_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */
|
/* virtual */
|
||||||
BSoundFile::~BSoundFile()
|
BSoundFile::~BSoundFile()
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
delete fSoundFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BSoundFile::InitCheck() const
|
BSoundFile::InitCheck() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
if (!fSoundFile) {
|
||||||
|
return B_NO_INIT;
|
||||||
return B_OK;
|
}
|
||||||
|
return fSoundFile->InitCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -42,169 +46,158 @@ status_t
|
|||||||
BSoundFile::SetTo(const entry_ref *ref,
|
BSoundFile::SetTo(const entry_ref *ref,
|
||||||
uint32 open_mode)
|
uint32 open_mode)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
if (fMediaTrack) {
|
||||||
|
BMediaTrack * track = fMediaTrack;
|
||||||
return B_ERROR;
|
fMediaTrack = 0;
|
||||||
|
fMediaFile->ReleaseTrack(track);
|
||||||
|
}
|
||||||
|
if (fMediaFile) {
|
||||||
|
BMediaFile * file = fMediaFile;
|
||||||
|
fMediaFile = 0;
|
||||||
|
delete file;
|
||||||
|
}
|
||||||
|
if (fSoundFile) {
|
||||||
|
BFile * file = fSoundFile;
|
||||||
|
fSoundFile = 0;
|
||||||
|
delete file;
|
||||||
|
}
|
||||||
|
if (open_mode == B_READ_ONLY) {
|
||||||
|
return _ref_to_file(ref);
|
||||||
|
} else {
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::FileFormat() const
|
BSoundFile::FileFormat() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fFileFormat;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::SamplingRate() const
|
BSoundFile::SamplingRate() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fSamplingRate;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::CountChannels() const
|
BSoundFile::CountChannels() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fChannelCount;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::SampleSize() const
|
BSoundFile::SampleSize() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fSampleSize;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::ByteOrder() const
|
BSoundFile::ByteOrder() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fByteOrder;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::SampleFormat() const
|
BSoundFile::SampleFormat() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fSampleFormat;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::FrameSize() const
|
BSoundFile::FrameSize() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fSampleSize * fChannelCount;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
off_t
|
off_t
|
||||||
BSoundFile::CountFrames() const
|
BSoundFile::CountFrames() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fFrameCount;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BSoundFile::IsCompressed() const
|
BSoundFile::IsCompressed() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fIsCompressed;
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BSoundFile::CompressionType() const
|
BSoundFile::CompressionType() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fCompressionType;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
BSoundFile::CompressionName() const
|
BSoundFile::CompressionName() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fCompressionName;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ int32
|
/* virtual */ int32
|
||||||
BSoundFile::SetFileFormat(int32 format)
|
BSoundFile::SetFileFormat(int32 format)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fFileFormat = format;
|
||||||
|
return fFileFormat;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ int32
|
/* virtual */ int32
|
||||||
BSoundFile::SetSamplingRate(int32 fps)
|
BSoundFile::SetSamplingRate(int32 fps)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fSamplingRate = fps;
|
||||||
|
return fSamplingRate;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ int32
|
/* virtual */ int32
|
||||||
BSoundFile::SetChannelCount(int32 spf)
|
BSoundFile::SetChannelCount(int32 spf)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fChannelCount = spf;
|
||||||
|
return fChannelCount;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ int32
|
/* virtual */ int32
|
||||||
BSoundFile::SetSampleSize(int32 bps)
|
BSoundFile::SetSampleSize(int32 bps)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fSampleSize = bps;
|
||||||
|
return fSampleSize;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ int32
|
/* virtual */ int32
|
||||||
BSoundFile::SetByteOrder(int32 bord)
|
BSoundFile::SetByteOrder(int32 bord)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fByteOrder = bord;
|
||||||
|
return fByteOrder;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ int32
|
/* virtual */ int32
|
||||||
BSoundFile::SetSampleFormat(int32 fmt)
|
BSoundFile::SetSampleFormat(int32 fmt)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fSampleFormat = fmt;
|
||||||
|
return fSampleFormat;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virtual */ int32
|
/* virtual */ int32
|
||||||
BSoundFile::SetCompressionType(int32 type)
|
BSoundFile::SetCompressionType(int32 type)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +205,6 @@ BSoundFile::SetCompressionType(int32 type)
|
|||||||
/* virtual */ char *
|
/* virtual */ char *
|
||||||
BSoundFile::SetCompressionName(char *name)
|
BSoundFile::SetCompressionName(char *name)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,8 +212,6 @@ BSoundFile::SetCompressionName(char *name)
|
|||||||
/* virtual */ bool
|
/* virtual */ bool
|
||||||
BSoundFile::SetIsCompressed(bool tf)
|
BSoundFile::SetIsCompressed(bool tf)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,9 +228,8 @@ BSoundFile::SetDataLocation(off_t offset)
|
|||||||
/* virtual */ off_t
|
/* virtual */ off_t
|
||||||
BSoundFile::SetFrameCount(off_t count)
|
BSoundFile::SetFrameCount(off_t count)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fFrameCount = count;
|
||||||
|
return fFrameCount;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -276,18 +265,14 @@ BSoundFile::SeekToFrame(off_t n)
|
|||||||
off_t
|
off_t
|
||||||
BSoundFile::FrameIndex() const
|
BSoundFile::FrameIndex() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fFrameIndex;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
off_t
|
off_t
|
||||||
BSoundFile::FramesRemaining() const
|
BSoundFile::FramesRemaining() const
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
return fFrameCount - FrameIndex();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
@@ -302,16 +287,104 @@ void BSoundFile::_ReservedSoundFile3() {}
|
|||||||
void
|
void
|
||||||
BSoundFile::_init_raw_stats()
|
BSoundFile::_init_raw_stats()
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
fSoundFile = 0;
|
||||||
|
fMediaFile = 0;
|
||||||
|
fMediaTrack = 0;
|
||||||
|
fFileFormat = B_UNKNOWN_FILE;
|
||||||
|
fSamplingRate = 44100;
|
||||||
|
fChannelCount = 2;
|
||||||
|
fSampleSize = 2;
|
||||||
|
fByteOrder = B_BIG_ENDIAN;
|
||||||
|
fSampleFormat = B_LINEAR_SAMPLES;
|
||||||
|
fFrameCount = 0;
|
||||||
|
fFrameIndex = 0;
|
||||||
|
fIsCompressed = false;
|
||||||
|
fCompressionType = -1;
|
||||||
|
fCompressionName = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BSoundFile::_ref_to_file(const entry_ref *ref)
|
BSoundFile::_ref_to_file(const entry_ref *ref)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED();
|
status_t status;
|
||||||
|
BFile * file = new BFile(ref,B_READ_ONLY);
|
||||||
return B_ERROR;
|
status = file->InitCheck();
|
||||||
|
if (status != B_OK) {
|
||||||
|
fSoundFile = file;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
BMediaFile * media = new BMediaFile(file);
|
||||||
|
status = media->InitCheck();
|
||||||
|
if (status != B_OK) {
|
||||||
|
delete media;
|
||||||
|
delete file;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
media_file_format mfi;
|
||||||
|
media->GetFileFormatInfo(&mfi);
|
||||||
|
switch (mfi.family) {
|
||||||
|
case B_AIFF_FORMAT_FAMILY: fFileFormat = B_AIFF_FILE; break;
|
||||||
|
case B_WAV_FORMAT_FAMILY: fFileFormat = B_WAVE_FILE; break;
|
||||||
|
default: fFileFormat = B_UNKNOWN_FILE; break;
|
||||||
|
}
|
||||||
|
int trackNum = 0;
|
||||||
|
BMediaTrack * track = 0;
|
||||||
|
media_format mf;
|
||||||
|
while (trackNum < media->CountTracks()) {
|
||||||
|
track = media->TrackAt(trackNum);
|
||||||
|
status = track->EncodedFormat(&mf);
|
||||||
|
if (status != B_OK) {
|
||||||
|
media->ReleaseTrack(track);
|
||||||
|
delete media;
|
||||||
|
delete file;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
if (mf.IsAudio()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
media->ReleaseTrack(track);
|
||||||
|
track = 0;
|
||||||
|
}
|
||||||
|
if (track == 0) {
|
||||||
|
delete media;
|
||||||
|
delete file;
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
media_raw_audio_format * raw = 0;
|
||||||
|
if (mf.type == B_MEDIA_ENCODED_AUDIO) {
|
||||||
|
raw = &mf.u.encoded_audio.output;
|
||||||
|
}
|
||||||
|
if (mf.type == B_MEDIA_RAW_AUDIO) {
|
||||||
|
raw = &mf.u.raw_audio;
|
||||||
|
}
|
||||||
|
fSamplingRate = (int)raw->frame_rate;
|
||||||
|
fChannelCount = raw->channel_count;
|
||||||
|
fSampleSize = raw->format & 0xf;
|
||||||
|
fByteOrder = raw->byte_order;
|
||||||
|
switch (raw->format) {
|
||||||
|
case media_raw_audio_format::B_AUDIO_FLOAT:
|
||||||
|
fSampleFormat = B_FLOAT_SAMPLES;
|
||||||
|
break;
|
||||||
|
case media_raw_audio_format::B_AUDIO_INT:
|
||||||
|
case media_raw_audio_format::B_AUDIO_SHORT:
|
||||||
|
case media_raw_audio_format::B_AUDIO_UCHAR:
|
||||||
|
case media_raw_audio_format::B_AUDIO_CHAR:
|
||||||
|
fSampleFormat = B_LINEAR_SAMPLES;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fSampleFormat = B_UNDEFINED_SAMPLES;
|
||||||
|
}
|
||||||
|
fByteOffset = 0;
|
||||||
|
fFrameCount = track->CountFrames();
|
||||||
|
fFrameIndex = 0;
|
||||||
|
if (mf.type == B_MEDIA_ENCODED_AUDIO) {
|
||||||
|
fIsCompressed = true;
|
||||||
|
fCompressionType = mf.u.encoded_audio.encoding;
|
||||||
|
}
|
||||||
|
fMediaFile = media;
|
||||||
|
fMediaTrack = track;
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user