Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AudioStimualtionProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pintér Gergő
AudioStimualtionProject
Commits
5f8c7b93
Commit
5f8c7b93
authored
1 year ago
by
Pintér Gergő
Browse files
Options
Downloads
Patches
Plain Diff
Működő, hang, az eredeti tervvel
parent
a1d58a86
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
audio_feedback.py
+24
-10
24 additions, 10 deletions
audio_feedback.py
with
24 additions
and
10 deletions
audio_feedback.py
+
24
−
10
View file @
5f8c7b93
...
...
@@ -4,6 +4,7 @@ import time
import
threading
import
constants
as
c
# Globális változók
sample_rate
=
44100
phase_left
=
0
...
...
@@ -12,6 +13,9 @@ is_playing = False
last_call_time
=
0
controller_lock
=
threading
.
Lock
()
stream
=
None
volume
=
0.2
max_volume
=
1
past_first_N3
=
False
def
check_pip
(
tester_list
):
...
...
@@ -22,16 +26,21 @@ def check_pip(tester_list):
- Itt implementáljuk a logikát, ami dönt a feedbackról. Ez visszamenőleg tudja elemezni a listát
és ennek megfelelően dönt
- Meghívhatja az audio_controller és az analyze_file is
- Addig nincsen feedback, amég az első N3 ciklus meg nem történt, hogy az alvás megszilárduljon.
:param tester_list: Yasa_output_list, vagy kimentett lista
:return: bool, szükséges e az audiofeedback az aktuális epochra
"""
if
len
(
tester_list
)
>
60
:
global
past_first_N3
if
not
past_first_N3
:
last_ten
=
[{
k
:
v
for
k
,
v
in
elem
.
items
()
if
k
!=
'
Stage
'
}
for
elem
in
tester_list
[
-
10
:]]
deep_sleep_met
=
all
((
elem
[
'
N3
'
]
>
0.6
)
for
elem
in
last_ten
)
if
deep_sleep_met
:
past_first_N3
=
True
else
:
last_probas
=
[{
k
:
v
for
k
,
v
in
elem
.
items
()
if
k
!=
'
Stage
'
}
for
elem
in
tester_list
[
-
c
.
CHECK_LEN
:]]
all_conditions_met
=
all
((
elem
[
'
N2
'
]
+
elem
[
'
N3
'
]
>
0.7
)
and
(
elem
[
'
N3
'
]
<=
0.5
)
for
elem
in
last_probas
)
pre_check_conditions_met
=
all
(
(
elem
[
'
N2
'
]
+
elem
[
'
N3
'
]
+
elem
[
'
R
'
]
>=
0.6
)
for
elem
in
tester_list
[
-
c
.
CHECK_LEN
-
15
:
-
c
.
CHECK_LEN
])
return
all_conditions_met
and
pre_check_conditions_met
all_conditions_met
=
all
((
elem
[
'
N2
'
]
+
elem
[
'
N3
'
]
>
c
.
N2_N3
)
and
(
elem
[
'
N3
'
]
<=
c
.
N3
)
for
elem
in
last_probas
)
return
all_conditions_met
def
callback
(
outdata
,
frames
,
time
,
status
):
...
...
@@ -42,10 +51,10 @@ def callback(outdata, frames, time, status):
- Létrehozza és betölti folyamatosan a binautális ütemet a streameléshez, és követi a fázist
- Korrigálja a túlcsordulást a végén
"""
global
phase_left
,
phase_right
global
phase_left
,
phase_right
,
volume
t
=
(
np
.
arange
(
frames
)
/
sample_rate
).
reshape
(
-
1
,
1
)
left
=
np
.
sin
(
2
*
np
.
pi
*
c
.
FREQUENCY_LEFT
*
t
+
phase_left
)
right
=
np
.
sin
(
2
*
np
.
pi
*
c
.
FREQUENCY_RIGHT
*
t
+
phase_right
)
left
=
np
.
sin
(
2
*
np
.
pi
*
c
.
FREQUENCY_LEFT
*
t
+
phase_left
)
*
volume
right
=
np
.
sin
(
2
*
np
.
pi
*
c
.
FREQUENCY_RIGHT
*
t
+
phase_right
)
*
volume
outdata
[:]
=
np
.
hstack
([
left
,
right
])
phase_left
+=
2
*
np
.
pi
*
c
.
FREQUENCY_LEFT
*
frames
/
sample_rate
phase_right
+=
2
*
np
.
pi
*
c
.
FREQUENCY_RIGHT
*
frames
/
sample_rate
...
...
@@ -64,8 +73,9 @@ def start_stream():
lesz kellően, és nem recseg amikor nagyobb számításigény merül fel a kódban
"""
global
is_playing
,
stream
global
is_playing
,
stream
,
volume
if
not
is_playing
:
volume
=
0.2
stream
=
sd
.
OutputStream
(
channels
=
2
,
callback
=
callback
,
samplerate
=
sample_rate
,
blocksize
=
sample_rate
)
stream
.
start
()
is_playing
=
True
...
...
@@ -93,7 +103,7 @@ def audio_controller(yasa_output_list):
lejátszás
- Ha valami miatt egy percig nincs hívás leállítja a lejátszást
"""
global
is_playing
,
last_call_time
,
controller_lock
global
is_playing
,
last_call_time
,
controller_lock
,
volume
should_play
=
check_pip
(
yasa_output_list
)
with
controller_lock
:
current_time
=
time
.
time
()
...
...
@@ -106,5 +116,9 @@ def audio_controller(yasa_output_list):
start_stream
()
elif
not
should_play
and
is_playing
:
stop_stream
()
elif
should_play
and
is_playing
:
volume
=
min
(
volume
+
0.2
,
max_volume
)
last_call_time
=
current_time
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment