11import { useCallback , useEffect , useState } from 'react' ;
2- import { View , StyleSheet , ScrollView } from 'react-native' ;
2+
3+ import { ScrollView , StyleSheet , Text , View } from 'react-native' ;
34import { computeAmplitude } from 'react-native-audio-analyzer' ;
5+ import { robustScale , sample , scale , trimmedScale } from '../../src/helpers' ;
46
5- export default function Index ( ) {
7+ export default function App ( ) {
68 const [ data , setData ] = useState < number [ ] > ( [ ] ) ;
9+
710 const run = useCallback ( async ( ) => {
811 try {
912 const result = computeAmplitude (
1013 '/data/data/audioanalyzer.example/files/sample.mp3' ,
11- 1000
14+ 100
1215 ) ;
1316 setData ( result ) ;
1417 } catch ( raw ) {
@@ -21,29 +24,80 @@ export default function Index() {
2124 run ( ) ;
2225 } , [ run ] ) ;
2326
27+ const results = [
28+ {
29+ title : 'Original:' ,
30+ data : data . map ( ( value , index ) => (
31+ < View key = { index } style = { [ styles . item , { height : value * 100 } ] } />
32+ ) ) ,
33+ } ,
34+ {
35+ title : 'Trimmed scale:' ,
36+ data : trimmedScale ( data , 0 , 1 ) . map ( ( value , index ) => (
37+ < View key = { index } style = { [ styles . item , { height : value * 100 } ] } />
38+ ) ) ,
39+ } ,
40+ {
41+ title : 'Robust scale:' ,
42+ data : robustScale ( data , 0 , 1 ) . map ( ( value , index ) => (
43+ < View key = { index } style = { [ styles . item , { height : value * 100 } ] } />
44+ ) ) ,
45+ } ,
46+ {
47+ title : 'Scale + sample:' ,
48+ data : scale ( sample ( data , 35 ) ) . map ( ( value , index ) => (
49+ < View key = { index } style = { [ styles . item , { height : value * 100 } ] } />
50+ ) ) ,
51+ } ,
52+ {
53+ title : 'Scale:' ,
54+ data : scale ( data ) . map ( ( value , index ) => (
55+ < View key = { index } style = { [ styles . item , { height : value * 100 } ] } />
56+ ) ) ,
57+ } ,
58+ ] ;
59+
2460 return (
25- < ScrollView horizontal contentContainerStyle = { styles . root } >
26- < View style = { styles . container } >
27- { data . map ( ( item , index ) => (
28- < View key = { index } style = { [ styles . item , { height : 500 * item } ] } />
61+ < View style = { styles . container } >
62+ < View >
63+ { results . map ( ( _ , index ) => (
64+ < View style = { styles . example } key = { index } >
65+ < Text style = { styles . title } > { _ . title } </ Text >
66+ < ScrollView horizontal style = { styles . scroll } >
67+ < View style = { styles . row } > { _ . data } </ View >
68+ </ ScrollView >
69+ </ View >
2970 ) ) }
3071 </ View >
31- </ ScrollView >
72+ </ View >
3273 ) ;
3374}
3475
3576const styles = StyleSheet . create ( {
36- root : {
37- flexGrow : 1 ,
38- } ,
3977 container : {
4078 flex : 1 ,
41- columnGap : 1 ,
79+ justifyContent : 'center' ,
80+ backgroundColor : '#ffffff' ,
81+ } ,
82+ loader : {
83+ padding : 30 ,
84+ } ,
85+ row : {
4286 flexDirection : 'row' ,
4387 alignItems : 'center' ,
4488 } ,
89+ title : {
90+ marginBottom : 5 ,
91+ } ,
92+ example : {
93+ padding : 10 ,
94+ } ,
95+ scroll : {
96+ maxHeight : 200 ,
97+ } ,
4598 item : {
4699 width : 3 ,
47- backgroundColor : 'red' ,
100+ backgroundColor : 'blue' ,
101+ marginHorizontal : 2 ,
48102 } ,
49103} ) ;
0 commit comments