Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/openal-0.0.8/src/al_mixmanager.c @ 17

Last change on this file since 17 was 17, checked in by landauf, 16 years ago

added openal

File size: 2.7 KB
Line 
1/* -*- mode: C; tab-width:8; c-basic-offset:8 -*-
2 * vi:set ts=8:
3 *
4 * al_mixmanager.c
5 *
6 * Definition and manipulated of ALMixManager objects.
7 */
8#include "al_siteconfig.h"
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13
14#include "al_debug.h"
15#include "al_types.h"
16#include "al_mixmanager.h"
17
18#include "mixaudio16.h"
19
20/*
21 * _alMixManagerInit( ALMixManager *mixman, ALuint size )
22 *
23 * Initializes the already allocated ALMixManager object *mixman, to
24 * accomodate at least size entries.
25 */
26ALboolean _alMixManagerInit( ALMixManager *mixman, ALuint size ) {
27        void *temp;
28
29        if(size == 0) {
30                return AL_FALSE;
31        }
32
33        if(size > MAXMIXSOURCES) {
34                return AL_FALSE;
35        }
36
37        mixman->size = size;
38        mixman->index = 0;
39
40        temp = realloc(mixman->pool, size * sizeof *mixman->pool);
41        if(temp == NULL) {
42                perror("malloc");
43                return AL_FALSE;
44        }
45        mixman->pool = temp;
46
47        memset(mixman->pool, 0, size * sizeof *mixman->pool);
48
49        return AL_TRUE;
50}
51
52/*
53 * _alMixManagerDestroy( ALMixManager *mixman )
54 *
55 * Performs finalization on the ALMixManager object *mixman.
56 */
57void _alMixManagerDestroy( ALMixManager *mixman ) {
58        free( mixman->pool );
59        mixman->pool = NULL;
60
61        mixman->index = 0;
62        mixman->size  = 0;
63
64        /* let caller free mixman, if needed */
65
66        return;
67}
68
69
70/*
71 * _alMixManagerAdd( ALMixManager *mixman, ALvoid *dataptr, int bytes_to_write )
72 *
73 * Adds an entry to the ALMixManager object *mixman, with data dataptr of
74 * length bytes_to_write in bytes.
75 *
76 * assumes locked mixer
77 *
78 * FIXME: sort by bytes?
79 */
80void _alMixManagerAdd( ALMixManager *mixman, void *dataptr, int bytes_to_write ) {
81        void *temp;
82
83        if(mixman->index >= mixman->size) {
84                /* time to resize */
85                int newsize = mixman->size * 2;
86
87                temp = realloc(mixman->pool, newsize * sizeof *mixman->pool);
88                if(temp == NULL) {
89                        /* oh dear */
90                        return;
91                }
92
93                mixman->pool = temp;
94                mixman->size = newsize;
95        }
96
97        mixman->pool[mixman->index].data  = dataptr;
98        mixman->pool[mixman->index].bytes = bytes_to_write;
99
100        mixman->index++;
101
102        return;
103}
104
105
106/*
107 * _alMixManagerMix( ALMixManager *mixman, ALMixFunc *mf, ALvoid *dataptr )
108 *
109 * Mixes each entry in ALMixManager *mixman, using mixing functions from
110 * ALMixFunc, populating dataptr.
111 *
112 *  assumes locked mixer
113 */
114void _alMixManagerMix( ALMixManager *mixman, ALMixFunc *mf, ALvoid *dataptr ) {
115        if( mixman == NULL ) {
116                return;
117        }
118
119        if( mf == NULL ) {
120                return;
121        }
122
123        if(mixman->index > mf->max) {
124                /* bite the bullet and do it the long way */
125                mf->func_n(dataptr, mixman->pool, mixman->index);
126        } else {
127                /* do the mixing */
128                mf->funcs[mixman->index](dataptr, mixman->pool);
129        }
130
131        while(mixman->index--) {
132                mixman->pool[mixman->index].data = NULL;
133        }
134
135        /* reset index */
136        mixman->index = 0;
137
138        return;
139}
Note: See TracBrowser for help on using the repository browser.