-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:iplayfast/arduino-scope
Conflicts: CMakeLists.txt main.cpp
- Loading branch information
Showing
6 changed files
with
210 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "line.h" | ||
|
||
|
||
line::line() { for (int i=0; i< CHANNELNUM; i++) {visible[i] = true; scale[i] = 1;}; end = 0; } | ||
void line::AddSample(int* val) { timemark[end]=*val++; for (int i=0; i< CHANNELNUM; i++){ value[i][end] = *val++; }; end++; if (end==TRACELENGTH) end--; } | ||
int line::GetChSample(int start, int ch) const { if (start<0) start=0; if (start>=end) return 0; else return value[ch][start] / scale[ch]; } | ||
int line::GetTime(int start) { return timemark[start]; } | ||
void line::IncScale(int ch) { if (scale[ch]>1) scale[ch]--; } | ||
void line::DecScale(int ch) { if (scale[ch]<512) scale[ch]++; } | ||
bool line::IsVisible(int ch) const { return visible[ch]; } | ||
void line::ToggleVisible(int ch) { visible[ch] = !visible[ch]; } | ||
int line::GetScale(int ch) const { return scale[ch]; } | ||
void line::Reset() { end=0; } | ||
int line::GetBaseTime() const { return timemark[0]; } | ||
int line::GetMaxTime() const { if (end>0) return timemark[end-1]; else return timemark[0]; } | ||
int line::GetEnd() const { return end; } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef LINES_H | ||
#define LINES_H | ||
|
||
#define TRACELENGTH 10000 | ||
#define CHANNELNUM 2 | ||
|
||
|
||
class line | ||
{ | ||
int timemark[TRACELENGTH]; | ||
int value[CHANNELNUM][TRACELENGTH]; | ||
int end; | ||
bool visible[CHANNELNUM]; | ||
int scale[CHANNELNUM]; | ||
|
||
public: | ||
line(); | ||
void AddSample(int* val); | ||
int GetChSample(int start, int ch) const; | ||
int GetTime(int start); | ||
void IncScale(int ch); | ||
void DecScale(int ch); | ||
bool IsVisible(int ch) const; | ||
void ToggleVisible(int ch); | ||
int GetScale(int ch) const; | ||
void Reset(); | ||
int GetBaseTime() const; | ||
int GetMaxTime() const; | ||
int GetEnd() const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifdef WITH_SOUND | ||
#include "sound.h" | ||
|
||
int loadWave(const char* filename, waveFile* waveFile) | ||
{ | ||
FILE* file; | ||
/* allocate space for the wave header */ | ||
waveFile->header = (waveHeader *) malloc(sizeof(waveHeader)); | ||
/* make sure the file is there and open it read-only (binary) */ | ||
if ((file = fopen(filename, "rb")) == NULL) { | ||
printf("File not found : %s\n", filename); | ||
return 0; | ||
} | ||
/* read the wave header */ | ||
if (!fread(waveFile->header, sizeof(waveHeader), 1, file)) { | ||
printf("Error reading file!\n"); | ||
return 0; | ||
} | ||
/* check if it is a riff wave file */ | ||
if (waveFile->header->chunkID != RIFF || | ||
waveFile->header->format != WAVE || | ||
waveFile->header->subChunk1ID != FMT || | ||
waveFile->header->subChunk2ID != DATA) { | ||
printf("Soundfile %s not in wave format!\n", filename); | ||
return 0; | ||
} | ||
/* we can only handle uncompressed, PCM encoded waves! */ | ||
if (waveFile->header->audioFormat != 1) { | ||
printf("Soundfile not PCM encoded!\n"); | ||
return 0; | ||
} | ||
/* we can only handle up to two channels (stereo) */ | ||
if (waveFile->header->numberOfChannels > 2) { | ||
printf("Soundfile has more than 2 channels!\n"); | ||
return 0; | ||
} | ||
waveFile->sampleData = (unsigned char *) malloc(waveFile->header->subChunk2Size); | ||
fseek(file, sizeof(waveHeader), SEEK_SET); | ||
if (!fread(waveFile->sampleData, waveFile->header->subChunk2Size, 1, | ||
file)) { | ||
printf("Error loading file!\n"); | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
pa_simple *s; | ||
|
||
void playSound(waveFile* sound) { | ||
int error; | ||
pa_simple_write (s, | ||
sound->sampleData, | ||
sound->header->subChunk2Size, | ||
&error); | ||
} | ||
|
||
void killsound() | ||
{ | ||
pa_simple_free(s); | ||
} | ||
// printf("%d %d\n",x,70 + lines[0].GetSample(x)); | ||
|
||
int initSound(int bitsPerSample, int numberOfChannels, int samplingRate) | ||
{ | ||
pa_sample_spec ss; | ||
|
||
ss.format = PA_SAMPLE_S16NE; | ||
ss.channels = 2; | ||
ss.rate = 44100; | ||
|
||
s = pa_simple_new(NULL, // Use the default server. | ||
"Fooapp", // Our application's name. | ||
PA_STREAM_PLAYBACK, | ||
NULL, // Use the default device. | ||
"Music", // Description of our stream. | ||
&ss, // Our sample format. | ||
NULL, // Use default channel map | ||
NULL, // Use default buffering attributes. | ||
NULL // Ignore error code. | ||
); | ||
|
||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
#else | ||
|
||
int loadWave(const char* filename, waveFile* waveFile) | ||
{ | ||
return 1; | ||
}; | ||
|
||
void playSound(waveFile* sound) {}; | ||
void killsound() {}; | ||
int initSound(int bitsPerSample, int numberOfChannels, int samplingRate) | ||
{ | ||
return 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifdef WITH_SOUND | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <sys/soundcard.h> | ||
#include <simple.h> | ||
#define RIFF 1179011410 /* little endian value for ASCII-encoded 'RIFF' */ | ||
#define WAVE 1163280727 /* little endian value for ASCII-encoded 'WAVE' */ | ||
#define FMT 544501094 /* little endian value for ASCII-encoded 'fmt' */ | ||
#define DATA 1635017060 /* little endian value for ASCII-encoded 'data' */ | ||
|
||
#endif | ||
|
||
typedef struct { | ||
unsigned int chunkID; /* ASCII: 'RIFF' */ | ||
unsigned int chunkSize; /* filelength - 8 */ | ||
unsigned int format; /* ASCII: 'WAVE' */ | ||
|
||
unsigned int subChunk1ID; /* ASCII: 'fmt ' */ | ||
unsigned int subChunk1Size; /* length of sub chunk, 16 for PCM*/ | ||
unsigned short int audioFormat; /* should be 1 for PCM */ | ||
unsigned short int numberOfChannels; /* 1 Mono, 2 Stereo */ | ||
unsigned int sampleRate; /* sample frequency */ | ||
unsigned int byteRate; /* sampleRate * numberOfChannels * bitsPerSample/8 */ | ||
|
||
unsigned short int blockAlign; /* numberOfChannels * bitsPerSample/8 */ | ||
unsigned short int bitsPerSample; /* 8, 16 bit */ | ||
|
||
unsigned int subChunk2ID; /* ASCII: 'data' */ | ||
unsigned int subChunk2Size; /* size of the sample data */ | ||
} waveHeader; | ||
|
||
typedef struct { | ||
waveHeader* header; | ||
unsigned char* sampleData; | ||
} waveFile; | ||
|
||
|
||
int loadWave(const char* filename, waveFile* waveFile); | ||
void playSound(waveFile* sound); | ||
void killsound(); | ||
int initSound(int bitsPerSample, int numberOfChannels, int samplingRate); | ||
|