Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
riot committed Mar 26, 2024
1 parent 32f1d41 commit 39bcb60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 38 deletions.
15 changes: 0 additions & 15 deletions tests/periph_pdm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,22 @@ int start_recording_cmd(int argc, char **argv)
(void)argv;
_main_thread_pid = thread_getpid();
#if !PDM_DATA_PRINT_BINARY
//puts("PDM peripheral driver test\n");
#endif

/* msg_t temp;
for (unsigned i = 0; i<1; i++)
{
msg_receive(&temp);
} */
for (unsigned repeat = 0; repeat < NEW_BUF_SIZE / PDM_BUF_SIZE; repeat++) {
msg_t msg;
msg_receive(&msg);
int16_t *buf = (int16_t *)msg.content.ptr;
#if PDM_DATA_PRINT_BINARY
stdio_write((uint8_t *)buf, PDM_BUF_SIZE >> 2);
#else
/* printf("Start of the buffer\n");
for (unsigned idx = 0; idx < PDM_BUF_SIZE; ++idx) {
printf("%i\n", buf[idx]);
buf_size = idx;
}
printf("End of the buffer\n");
printf("%d\n", buf_size); */

// Copy PDM_BUF_SIZE to NEW_BUF_SIZE repeatedly
for (unsigned idx = 0; idx < PDM_BUF_SIZE; idx++) {
new_buf[repeat*PDM_BUF_SIZE+idx] = buf[idx];
}
#endif
}
// Parse the new_buf
//pdm_stop();
_main_thread_pid = KERNEL_PID_UNDEF;
printf("Start of the new buffer\n");
for (unsigned idx = 0; idx < NEW_BUF_SIZE ; idx++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
str1 = "Start of the new buffer".encode('ascii')
str2= "End of the new buffer".encode('ascii')

Check failure on line 15 in tests/periph_pdm/testing_pdm_conversion.py

View workflow job for this annotation

GitHub Actions / static-tests

E225 missing whitespace around operator

start_index_buf = 0
start_index_buf = 0

Check failure on line 17 in tests/periph_pdm/testing_pdm_conversion.py

View workflow job for this annotation

GitHub Actions / static-tests

trailing whitespace.
stop_index_buf = 0
start_found = False
buffer_number = 0
Expand All @@ -31,29 +31,24 @@
value = line.strip()
data[key] = value
if line.find(str1) != -1:
#print("Start Recording")
start_found = True
start_index_buf = key
if line.find(str2) != -1:

if start_found:
stop_index_buf = key
buffer_number = stop_index_buf - start_index_buf - 2
start = False
#print("Stop recording")
break
key +=1

print(start_index_buf)
print(start_index_buf)

Check failure on line 44 in tests/periph_pdm/testing_pdm_conversion.py

View workflow job for this annotation

GitHub Actions / static-tests

trailing whitespace.
print(stop_index_buf)
print(buffer_number)
ser.close()

# Extract the data within the specified range
data_to_plot = [int(data[i]) for i in range(start_index_buf+1, stop_index_buf)]
data_to_bytes = [int(data[i]).to_bytes(2,byteorder="little",signed=True) for i in range(start_index_buf+1, stop_index_buf)]
data_to_export = [(data[i]) for i in range(start_index_buf+1, stop_index_buf)]
#print(data_to_bytes)

# Save the data to 16-b file
# Open a file in binary write mode
Expand All @@ -62,22 +57,6 @@
# Write the binary data to the file
f.write(binary_data)

# Sample rate (Hz)
sample_rate = 16000

# Open a new wave file
with wave.open("output_wave.wav", "w") as output_wave:
# Set parameters for the wave file
output_wave.setnchannels(1) # Mono
output_wave.setsampwidth(2) # 2 bytes per sample for 16-bit audio
output_wave.setframerate(sample_rate)

# Convert data_to_plot to numpy array
data_np = np.array(data_to_bytes)

# Convert data to bytes and write to the wave file
output_wave.writeframes(data_np)

# Sample rate (Hz)
samplerate = 16000
length = 1
Expand All @@ -94,6 +73,7 @@
# Convert to (little-endian) 16 bit integers.
audio = (audio * (2 ** 15 - 1)).astype("<h")

# Save the data as a wave format
with wave.open("sound_new_buf.wav", "w") as f:
# Mono Channel
f.setnchannels(1)
Expand Down

0 comments on commit 39bcb60

Please sign in to comment.