Skip to content

Commit

Permalink
week 5 and 6 helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
djdunc committed Dec 14, 2021
1 parent 170a072 commit a8c620a
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
22 changes: 5 additions & 17 deletions Week4/arduino/micro_speech_CASA/arduino_audio_provider.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
/*
Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -26,7 +13,7 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
*/

#if defined(ARDUINO) && !defined(ARDUINO_ARDUINO_NANO33BLE)
#define ARDUINO_EXCLUDE_CODE
Expand All @@ -36,7 +23,8 @@ limitations under the License.

#include "audio_provider.h"

#include "PDM.h"
#include "PDM.h" // https://www.arduino.cc/en/Reference/PDM Pulse Density Modulation

#include "micro_features_micro_model_settings.h"

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/



/*
Performs the FFT and returns the audio frequency information Ch.7 p145
*/


#include "micro_features_micro_features_generator.h"

#include <cmath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/


/*
Performs the FFT and returns the audio frequency information Ch.7 p145
*/


#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
OV767X - Camera Capture Raw Bytes
This sketch reads a frame from the OmniVision OV7675 camera
and writes the bytes to the Serial port. Use the Procesing
sketch in the extras folder to visualize the camera output.
This example code is in the public domain.
*/

#include <Arduino_OV767X.h>

int bytesPerFrame;

byte data[176 * 144 * 2]; // QVGA: 320x240 X 2 bytes per pixel (RGB565)

void setup() {
Serial.begin(9600);
//while (!Serial);

if (!Camera.begin(QVGA, RGB565, 1, OV7675)) {
Serial.println("Failed to initialize camera!");
while (1);
}
Serial.println("Initialize camera!");

bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel();

// Optionally, enable the test pattern for testing
// Camera.testPattern();
}

void loop() {
Camera.readFrame(data);

Serial.write(data, bytesPerFrame);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
This sketch reads a raw Stream of RGB565 pixels
from the Serial port and displays the frame on
the window.
Use with the Examples -> CameraCaptureRawBytes Arduino sketch.
This example code is in the public domain.
*/

import processing.serial.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

Serial myPort;

// must match resolution used in the sketch
final int cameraWidth = 176;
final int cameraHeight = 144;

final int cameraBytesPerPixel = 2;

final int bytesPerFrame = cameraWidth * cameraHeight * cameraBytesPerPixel;

PImage myImage;

void setup()
{
size(176, 144);

// if you have only ONE serial port active
//myPort = new Serial(this, Serial.list()[0], 9600); // if you have only ONE serial port active

// if you know the serial port name
//myPort = new Serial(this, "COM3", 9600); // Windows
//myPort = new Serial(this, "/dev/ttyACM0", 9600); // Linux
myPort = new Serial(this, "/dev/cu.usbmodem14701", 9600); // Mac

// wait for full frame of bytes
myPort.buffer(bytesPerFrame);

myImage = createImage(cameraWidth, cameraHeight, RGB);
}

void draw()
{
image(myImage, 0, 0);
}

void serialEvent(Serial myPort) {
byte[] frameBuffer = new byte[bytesPerFrame];

// read the saw bytes in
myPort.readBytes(frameBuffer);

// create image to set byte values
PImage img = createImage(cameraWidth, cameraHeight, RGB);

// access raw bytes via byte buffer
ByteBuffer bb = ByteBuffer.wrap(frameBuffer);
bb.order(ByteOrder.BIG_ENDIAN);

int i = 0;

img.loadPixels();
while (bb.hasRemaining()) {
// read 16-bit pixel
short p = bb.getShort();

// convert RGB565 to RGB 24-bit
int r = ((p >> 11) & 0x1f) << 3;
int g = ((p >> 5) & 0x3f) << 2;
int b = ((p >> 0) & 0x1f) << 3;

// set pixel color
img.pixels[i++] = color(r, g, b);
}
img.updatePixels();

// assign image for next draw
myImage = img;
}
Binary file removed Week6/edgeimpulse.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Week6/helpers/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
if filename.endswith(".wav"):
song = AudioSegment.from_wav(os.path.join(directory, filename))
play(song)
time.sleep(10)
time.sleep(2)
continue
else:
continue

0 comments on commit a8c620a

Please sign in to comment.