Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/src/openal/openal-glue.h
ViewVC logotype

View of /trunk/sml3d/src/openal/openal-glue.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 891 - (download) (as text) (annotate)
Tue May 11 20:01:36 2010 UTC (9 years, 7 months ago) by jhr
File size: 2547 byte(s)
  Added audio-file loading support to OpenAL
/*! \file openal-glue.h
 *
 * \author John Reppy
 */

/*
 * COPYRIGHT (c) 2010 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * This code is based on code in the freealut-1.1.0 sources, which is
 * available from http://openal.org
 */

#ifndef _OPENAL_GLUE_H_
#define _OPENAL_GLUE_H_

#include "sml3d-config.h"
#include <stdlib.h>
#include <stdio.h>
#ifdef __APPLE__
#  include <OpenAL/al.h>
#else
#  include <AL/al.h>
#endif

// a data buffer of raw audio data; this data structure has all of the
// information needed to initialize an OpenAL buffer using alBufferData().
// NOTE: this data structure is designed to have the same offsets and size
// on 32 and 64-bit systems
typedef struct {
    int32_t	length;			// number of bytes of data
    int32_t	numChannels;		// number of channels
    int32_t	bitsPerSample;		// bits per channel (8 or 16)
    int32_t	sampleFrequency;	// sample frequency (Hz)
    void	*data;			// pointer to raw audio data
#if defined(WORDS_32)
    int32_t	pad;			// to keep the 32-bit and 64-bit sizes the same
#endif
} BufferData_t;

// an abstraction of a input data source.  For now, this type only represents
// files, but it might be extended to represent in-memory sources in the future.
typedef struct {
    char	*fileName;		// the source file name
    size_t	remainingLength;	// number of bytes remaining in the source
    FILE	*fileDescriptor;	// file pointer
    ALenum	error;			// holds code of last error (if any)
} InputStream_t;

// A function for translating encoded audio into raw audio data
typedef BufferData_t *(*Codec_t) (void *, size_t, ALint, int, float);


/***** Codecs *****/
BufferData_t *SML3D_RawCodec (void *data, size_t len, int nChans, int bitsPerSample, float freq);
BufferData_t *SML3D_PCM8sCodec (void *data, size_t len, int nChans, int bitsPerSample, float freq);
BufferData_t *SML3D_PCM16Codec (void *data, size_t len, int nChans, int bitsPerSample, float freq);
BufferData_t *SML3D_muLawCodec (void *data, size_t len, int nChans, int bitsPerSample, float freq);
BufferData_t *SML3D_ALawCodec (void *data, size_t len, int nChans, int bitsPerSample, float freq);

static inline BufferData_t *NewBufferData (
    void *data, size_t len, int nChans, int bitsPerSample, float freq)
{
    BufferData_t *buf = (BufferData_t *)malloc(sizeof(BufferData_t));

    if (buf != 0) {
	buf->data		= data;
	buf->length		= len;
	buf->numChannels	= nChans;
	buf->bitsPerSample	= bitsPerSample;
	buf->sampleFrequency	= freq;
    }
    return buf;
}

#endif /*! _OPENAL_GLUE_H_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0