From 985e3847e0861bb39dfc277d8fb1afebf3190c89 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Tue, 22 Dec 2009 13:22:32 +0100 Subject: [PATCH] Added audiere File client. NOT TESTED. --- stream/imp_client/audiere_file.cpp | 39 ++++++++++++++++++++++++++++++ stream/imp_client/audiere_file.h | 35 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 stream/imp_client/audiere_file.cpp create mode 100644 stream/imp_client/audiere_file.h diff --git a/stream/imp_client/audiere_file.cpp b/stream/imp_client/audiere_file.cpp new file mode 100644 index 000000000..ea8142eb4 --- /dev/null +++ b/stream/imp_client/audiere_file.cpp @@ -0,0 +1,39 @@ +#include "audiere_file.h" + +using namespace audiere; +using namespace Mangle::Stream; + +bool AudiereFile::seek(int pos, SeekMode mode) +{ + assert(inp->isSeekable); + assert(inp->hasPosition); + + if(mode == BEGIN) + { + // Absolute position + inp->seek(pos); + return inp->tell() == pos; + } + if(mode == CURRENT) + { + // Current position + int cpos = inp->tell(); + + // Seek to a elative position + inp->seek(cpos + pos); + return inp->tell() == (pos+cpos); + } + if(mode == END) + { + // Seeking from the end. This requires that we're able to get + // the entire size of the file. The pos also has to be + // non-positive. + assert(inp->hasSize); + assert(pos <= 0); + + size_t epos = inp->size(); + inp->seek(epos + pos); + return inp->tell() == (epos+pos); + } + assert(0 && "invalid seek mode"); +} diff --git a/stream/imp_client/audiere_file.h b/stream/imp_client/audiere_file.h new file mode 100644 index 000000000..201a7629a --- /dev/null +++ b/stream/imp_client/audiere_file.h @@ -0,0 +1,35 @@ +#ifndef MANGLE_STREAM_AUDIERECLIENT_H +#define MANGLE_STREAM_AUDIERECLIENT_H + +#include +#include +#include "iwrapper.h" + +namespace Mangle { +namespace Stream { + +/** @brief An Audiere::File that wraps a Mangle::Stream input. + + This lets Audiere read sound files from any generic archive or + file manager that supports Mangle streams. + */ +class AudiereFile : public audiere::File, _IWrapper +{ + public: + AudiereFile(InputStream *inp, bool autoDel=false) + : _IWrapper(inp, autoDel) {} + + /// Read 'count' bytes, return bytes successfully read + int read(void *buf, int count) + { return inp->read(buf,count); } + + /// Seek, relative to specified seek mode. Returns true if successful. + bool seek(int pos, audiere::SeekMode mode); + + /// Get current position + int tell() + { assert(inp->hasPosition); return inp->tell(); } +}; + +}} // namespaces +#endif