summaryrefslogtreecommitdiff
path: root/source/io/SampleSourcePcm.h
blob: 0dfe789b23bc450ebcc66cf128d6fe8940ee1809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// SampleSourcePcm.h - MrsWatson
// Created by Nik Reiman on 1/2/12.
// Copyright (c) 2012 Teragon Audio. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//

#ifndef MrsWatson_InputSourcePcm_h
#define MrsWatson_InputSourcePcm_h

#include <stdio.h>

#include "io/SampleSource.h"

typedef struct {
    boolByte isStream;
    boolByte isLittleEndian;
    FILE *fileHandle;
    size_t dataBufferNumItems;
    short *interlacedPcmDataBuffer;

    ChannelCount numChannels;
    SampleRate sampleRate;
    unsigned short bitsPerSample;
} SampleSourcePcmDataMembers;
typedef SampleSourcePcmDataMembers *SampleSourcePcmData;
// this struct is actually the structure we need, looks like name just redefined later. sampleRate, numChannels, need to check those.
// ok awesome...so basically in order to check classes/structs, sometimes you have to look in the header file? yeah all structs and enums will be in header file
// and what is an enum (compared to a struct?) enumeration of possible values for one variable. like TYPE_MP3 TYPE_WAV etc. weird ok no worries

/**
 * Read raw PCM data to a floating-point sample buffer
 * @param self
 * @param sampleBuffer
 * @return Number of samples read
 * http://ghghgh.us/VST/
 * this documentation is still a bit tough for me to read
 */
size_t sampleSourcePcmRead(SampleSourcePcmData self, SampleBuffer sampleBuffer);

/**
 * Writes data from a sample buffer to a PCM output
 * @param self
 * @param sampleBuffer
 * @return Number of samples written
 */
size_t sampleSourcePcmWrite(SampleSourcePcmData self, const SampleBuffer sampleBuffer);

/**
 * Set the sample rate to be used for raw PCM file operations. This is most
 * relevant when writing a WAVE or a AIFF file, as the sample rate must be given
 * in the file header.
 * @param sampleSourcePtr
 * @param sampleRate Sample rate, in Hertz
 */
void sampleSourcePcmSetSampleRate(void *sampleSourcePtr, double sampleRate);

/**
 * Set the number of channels to be used for raw PCM file operations. Like the
 * sample, this is most relevant when writing a WAVE or a AIFF file.
 * @param sampleSourcePtr
 * @param numChannels Number of channels
 */
void sampleSourcePcmSetNumChannels(void *sampleSourcePtr, int numChannels);

/**
 * Free a PCM sample source and all associated data
 * @param sampleSourceDataPtr Pointer to sample source data
 */
void freeSampleSourceDataPcm(void *sampleSourceDataPtr);

#endif