Skip to content

Commit

Permalink
Update dart and added dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
antitim committed Aug 14, 2023
1 parent c181f0e commit cdd094a
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "analog-radio-example"
}
}
21 changes: 21 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Dart

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603

- name: Install dependencies
run: dart pub get

- name: Analyze project source
run: dart analyze
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.2.0

- Update to Dart 3.
- Make audio context dispose.
- Added more description.
- Added link to example.

# 1.1.0

- Update sound of noise. Added some random sawWaves.
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
# Analog radio emulator
# :radio: Analog radio emulator

[![pub package](https://img.shields.io/pub/v/analog_radio.svg)](https://pub.dev/packages/analog_radio)
[![Web Demo](https://img.shields.io/badge/Radio-Demo-FFB300.svg)](https://analog-radio-example.web.app/)

## About

This package adds distortion to the online audio stream, so it becomes like a radio receiver.

You can change the signal level so that it can be very weak and there will be a lot of interference.

The AudioContext Api is used. Therefore, it works only in the browser.

[Example](https://analog-radio-example.web.app/)

## Install

```sh
dart pub add analog_radio
```

## Using

```dart
// Creating radio instance. Will be created audiocontext with audio processing.
var radio = AnalogRadio();
// Start playing sound. You will be able to hear the radio noise
radio.turnOn();
// You set up the "radio receiver" for a specific audio stream with a signal level of 0.9.
// You will hear an audio stream with a slight addition of noise and distortion.
radio.tune('https://vip2.fastcast4u.com/proxy/classicrockdoug?mp=/1', 0.9);
// With a signal level of 0.3, the audio stream will be heard very poorly with a high level of interference
radio.tune('https://vip2.fastcast4u.com/proxy/classicrockdoug?mp=/1', 0.3);
// Stop playing sound
radio.turnOff();
```

## Developing

```sh
dart pub global activate webdev
dart pub get
webdev serve
webdev serve --release
```
10 changes: 10 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
3 changes: 3 additions & 0 deletions lib/src/analog_radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ abstract class AnalogRadio {

/// The radio is on
bool get running;

/// Dispose
void dispose();
}
5 changes: 5 additions & 0 deletions lib/src/audio_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class AudioProcessor implements AnalogRadio {
_stopWatching();
await _audioContext.suspend();
_dispatchCurrentState();
_audioPlayer.src = '';
}

@override
Expand Down Expand Up @@ -169,4 +170,8 @@ class AudioProcessor implements AnalogRadio {
String get url => _audioPlayer.src;
@override
bool get running => _audioContext.state == 'running';
@override
void dispose() {
_audioContext.close();
}
}
11 changes: 4 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ name: analog_radio
description: Utility for adding analog radio noise to online radio. Uses the WebAudio Api.
homepage: https://github.com/antitim/analog_radio
repository: https://github.com/antitim/analog_radio
version: 1.1.0
version: 1.2.0
environment:
sdk: ">=2.18.0 <3.0.0"
dependencies:
js: ^0.6.4
sdk: ">=3.0.0 <4.0.0"
dev_dependencies:
build_runner: ^2.3.3
build_test: ^2.1.5
build_web_compilers: ^3.2.7
build_runner: ^2.4.6
build_web_compilers: ^4.0.5

0 comments on commit cdd094a

Please sign in to comment.