mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 20:35:17 +02:00
35 lines
No EOL
837 B
C++
35 lines
No EOL
837 B
C++
//
|
|
// AudioSource.cpp
|
|
// interface
|
|
//
|
|
// Created by Stephen Birarda on 1/29/13.
|
|
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
|
//
|
|
|
|
#include "AudioSource.h"
|
|
|
|
AudioSource::~AudioSource()
|
|
{
|
|
delete[] sourceData;
|
|
}
|
|
|
|
|
|
int AudioSource::loadDataFromFile(const char *filename) {
|
|
FILE *soundFile = fopen(filename, "r");
|
|
|
|
// get length of file:
|
|
std::fseek(soundFile, 0, SEEK_END);
|
|
lengthInSamples = std::ftell(soundFile) / sizeof(int16_t);
|
|
std::rewind(soundFile);
|
|
|
|
sourceData = new int16_t[lengthInSamples];
|
|
size_t bytesRead = std::fread(sourceData, sizeof(int16_t), lengthInSamples, soundFile);
|
|
|
|
if (bytesRead != lengthInSamples) {
|
|
std::cout << "Error loading audio source data from file " << filename << "!\n";
|
|
}
|
|
|
|
std::fclose(soundFile);
|
|
|
|
return 0;
|
|
} |