pipe.h Source File

Main Page Modules Class Hierarchy Compound List File List Compound Members File Members

# pipe.h

Go to the documentation of this file.

    00001 /*
    00002   Copyright (c) 2001 Charles Samuels <charles@kde.org>
    00003   Copyright (c) 2002-2004 Denis Rojo <jaromil@dyne.org>
    00004
    00005   this pipe class was first written by Charles Samuels
    00006   and then heavily mutilated by jaromil
    00007
    00008   This library is free software; you can redistribute it and/or
    00009   modify it under the terms of the GNU Library General Public
    00010   License as published by the Free Software Foundation; either
    00011   version 2 of the License, or (at your option) any later version.
    00012
    00013   This library is distributed in the hope that it will be useful,
    00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00016   Library General Public License for more details.
    00017
    00018   You should have received a copy of the GNU Library General Public License
    00019   along with this library; see the file COPYING.LIB.  If not, write to
    00020   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00021   Boston, MA 02111-1307, USA.
    00022
    00023   $Id: pipe.h,v 1.4 2004/04/01 20:36:32 jaromil Exp $
    00024
    00025 */
    00026
    00032 #ifndef __PIPE_H__
    00033 #define __PIPE_H__
    00034
    00035 #include <pthread.h>
    00036 #include <string.h>
    00037 #include <inttypes.h>
    00038
    00070 class Pipe {
    00071 public:
    00072
    00076   Pipe(int size=16384);
    00078
    00079   ~Pipe();
    00081
    00094   int read(int length, void *data);
    00096
    00106   int read_float_intl(int samples, float *buf, int channels);
    00107
    00116   int read_float_bidi(int samples, float **buf, int channels);
    00118
    00128   int mix16stereo(int samples, int32_t *mix);
    00129
    00130   //    int peek(int length, void *data, bool block=true) const; // TODO
    00131
    00142   int write(int length, void *data);
    00143
    00149   void block(bool val);
    00150
    00151   bool blocking;
    00152
    00156   int size();
    00157
    00161   int space();
    00162
    00163   void flush();
    00164
    00165   void flush(int size);
    00167
    00168  private:
    00169   pthread_mutex_t _mutex;
    00170   void _thread_init() { pthread_mutex_init (&_mutex,NULL); };
    00171   void _thread_destroy() { pthread_mutex_destroy(&_mutex); };
    00172   void lock() { pthread_mutex_lock(&_mutex); };
    00173   void unlock() { pthread_mutex_unlock(&_mutex); };
    00174
    00175   void *buffer;
    00176   void *bufferEnd;
    00177
    00178   void *start;
    00179   void *end;
    00180
    00181   int pipesize;
    00182 };
    00183
    00184 #endif