[WIP] USB Host support (working)

Search This thread

zholy

Member
Sep 13, 2011
46
10

My apologies ... there was no intention, just silly translation assumption. In English you don't know the gender when you speak in first person (comparing to my language) and it happens that sometimes the gentle gender get left behind in the translational process. My apologies.

We're still working on recording, Skype and getting it to work without kicking mediaserver.

Mediaserver wouldn't be such problem - don't mind pressing a apk to make it work. It's just (as you described it) that it's like it would have it's own mind/will. I've tried a recording program and it worked nicely. After that I've tried Skype, but the recording worked for less then a second. So it makes a person like me wonder - what is different ?! (just the rates ???)

Volume works fine, you just have to use a USB keyboard or an USB audio adapter with HID volume buttons.
Don't you get a popup graphic of a speaker with dots under it?

Now I've made it to work through XorZones button remapping - but I had to restart the Nook 2x (?) to make it work. So now my left side controls the volume.
But the hardware button on my USB adapter don't make any effect ?! And mentioning it earlier, it looks exactly like yours. Comparing to your picture from 14th April I don't have a black dot next to HID. Probably that's why.
 
  • Like
Reactions: mrWax

Renate

Recognized Contributor / Inactive Recognized Dev
No black dot on 03:00 HID? That seems strange.
If you have a USB multimedia keyboard, try that.
Can you get it to show that the drivers are loaded?
Can you get the big speaker icon to pop up?

Personally, with only 4 buttons I'd be reluctant to give up 2 for volume.

Which application are you using to record?
What sample rates do you see in AudioCtl? Only 8K mono, 16K mono?
 
  • Like
Reactions: mrWax

Renate

Recognized Contributor / Inactive Recognized Dev
Ok, here's another step forward with getting audio fully functioning.
The Omap3ALSA driver is causing a bunch of trouble.
Disable it.

Code:
cd /system/lib/hw
mv alsa.zoom2.so alsa.zoom2.bak

Later: Well things are behaving differently now.
Note that it still says that it only does 8K mono and 16K mono, but it always records in 44.1 stereo.

Code:
# arecord --disable-resample --disable-channels -c 1 -r 8000 -f S16_LE -d 10 /sdcard/test.wav
Recording WAVE '/sdcard/test.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
Warning: rate is not accurate (requested = 8000Hz, got = 44100Hz)
 
Last edited:
  • Like
Reactions: mrWax

zholy

Member
Sep 13, 2011
46
10
No black dot on 03:00 HID? That seems strange.
If you have a USB multimedia keyboard, try that.
Can you get it to show that the drivers are loaded?
Will try today in school.
Can you get the big speaker icon to pop up?
Personally, with only 4 buttons I'd be reluctant to give up 2 for volume.
Yes, with XorZones buttons - it's there and working.
Which application are you using to record?
Fast Record
What sample rates do you see in AudioCtl? Only 8K mono, 16K mono?
I can see both of them. But I've never tried what's the real recordings value. Will do that today.

Could you specify a little bit more, what kind of trouble we are getting rid of when disabling the Omap3ALSA driver ? (just being noisy) ... thank you
 

Renate

Recognized Contributor / Inactive Recognized Dev
@zholy: When you record is the level of the audio correct?

The alsa.zoom2.so supports the SoC (System on a Chip) sound driver.
We are not using any of the interfaces in the chipset, the hardware is not there.
This causes a bunch of errors about "HandsfreeL" controls in logcat.
Moreover, it prevents the correct controls from working.

Controls may be configured in asound.conf
Be very careful, look at what controls your device has.
Misplaced punctuation in this file will brick your Nook.

This is a piece of my asound.conf

Code:
pcm.AndroidCapture
{
   type hooks
   slave.pcm
   {
      type hw
      card 1
      device 0
   }
   hooks.0
   {
      type ctl_elems
      hook_args
      [
         { name 'Mic Capture Switch' value on }
         { name 'Mic Capture Volume' value 12 }
         { name 'Mic Playback Switch' value on }
         { name 'Mic Playback Volume' value 20 }
      ]
   }
}

I'll have more on this soon.
 
  • Like
Reactions: mrWax

mrWax

Senior Member
Jan 31, 2012
147
24
hardw mod?

Seeing all these hardware advances especiale due to unexpectly-woman :) developer Renate NST makes me wonder whether hardw. mod wouldn't be good idea. - putting circuits of ebay-bought USB hub + USB sound card directly into NST casing.
Nevertheless I am gonna test cheapest :eek: usb soundcard on my nst today.

cheers
wax :cool:
 

zholy

Member
Sep 13, 2011
46
10
putting circuits of ebay-bought USB hub + USB sound card directly into NST casing.
That's what I was thinking of, but there are some tiny challenges :
- if you look at the shape of the Nook and the size of the socket - it will look a little bit ugly :( sticking out from the case a bit
- then is the question, whether to use only one socket for the 4 way plug (mic+earphones) like you have for mobile phones. That would be probably the best option, as then you would need only one hole
- or add only earphone socket, drill tiny holes and add an microphone directly into the nook
- what about volume buttons, would you make them usable or they would just been lost/not used ... (if they are present on the adapter)
- you would probably need a switch for turning this adapter on/off as there might be cases where you need only the keyboard, or memory stick and don't need audio (so you don't drain the battery)
- any combinations of these points

Why do you need a HUB ??? To make more USB sockets coming out from the NST ???

---------- Post added at 05:56 PM ---------- Previous post was at 05:33 PM ----------

Renate:
1. I've just checked the keyboard and I have the black dot on HID and the keyboard works ... but I don't have it on the audio adapter.
2. Please ignore the Fast Record apk, as it saves in .3gp format (8000)
3. Now I've tried "HQ Voice Rec Lite" ... it has a lot of settings, but it allowed me to use only 8000 and 16000. When I have played with different settings, and then played those files on my PC in VLC (all the media informations were exactly as I have set them)
4. Do you think that the extra lines in asound.conf (on my side) would cause that the drivers are not loaded/that the buttons don't work ???
5. You mentioned that I might brick the device = that I would need to reflash it with a backup, right ??? Is it possible to just make a copy of the orig. asound that I have now ... and if it get "bricked", start it with Noogie, replace the changed asound with the original and restart !?
6. could you explain a little bit, the values and the "on" status that is related to the buttons? How did you find out the values?

Thanks in advance.
 
  • Like
Reactions: mrWax

Renate

Recognized Contributor / Inactive Recognized Dev
There is the ALSA layer to audio and on top of that the Android layer.

If you run the alsa_amixer it will tell you a bunch of things.

Code:
alsa_amixer contents

The settings in asound.conf get applied when the corresponding alias is opened.

On my USB adapter there is the playback path, the record path and the record monitor path.
Each of them has a switch to turn on and a volume.
You can play with these values in alsa_amixer.

Right now, I only have Noogie and a Windows machine.
I can't mount the other partitions or access the files.
If I were to get in the habit of bricking my Nook I'd look for a better solution.

On my Nook right now you still just have the selections of 8K or 16K,
however, it records in stereo (from a mono source) at 44100 using either setting.

Such behavior cause data overruns in Skype.

@zholy, I have no idea why your USB buttons are not working, look at dmesg and logcat.
 

Renate

Recognized Contributor / Inactive Recognized Dev
Here is a /system/etc/asound.conf which seems to adjust the right things.
The names of controls is for my USB adapter which looks similar to the photo above.
Your control names may be something else.
Run alsa_amixer contents and look at the output.

Code:
defaults.ctl.card 1
defaults.pcm.card 1
defaults.timer.card 1

ctl.AndroidOut
{
   type hw
   card 1
}

ctl.AndroidIn
{
   type hw
   card 1
}

pcm.AndroidPlayback
{
   type hooks
   slave.pcm
   {
      type hw
      card 1
      device 0
   }
   hooks.0
   {
      type ctl_elems
      hook_args
      [
         { name 'Speaker Playback Switch' value on }
         { name 'Speaker Playback Volume' value [150 150] }
      ]
   }
}

pcm.AndroidPlayback_Speaker
{
   type hooks
   slave.pcm
   {
      type hw
      card 1
      device 0
   }
   hooks.0
   {
      type ctl_elems
      hook_args
      [
         { name 'Speaker Playback Switch' value on }
         { name 'Speaker Playback Volume' value [150 150] }
      ]
   }
}

pcm.AndroidPlayback_Speaker_normal
{
   type hooks
   slave.pcm
   {
      type hw
      card 1
      device 0
   }
   hooks.0
   {
      type ctl_elems
      hook_args
      [
         { name 'Speaker Playback Switch' value on }
         { name 'Speaker Playback Volume' value [150 150] }
      ]
   }
}

pcm.AndroidCapture
{
   type hooks
   slave.pcm
   {
      type hw
      card 1
      device 0
   }
   hooks.0
   {
      type ctl_elems
      hook_args
      [
         { name 'Mic Capture Switch' value on }
         { name 'Mic Capture Volume' value 12 }
         { name 'Mic Playback Switch' value on }
         { name 'Mic Playback Volume' value 20 }
      ]
   }
}

Also, I changed the defaults in alsa.default.so to 44.1 record.
That seemed to stop the Nook from always resetting it to 8000.
Binary fix: Offset 2270: 40 1f 00 00 => 44 ac 00 00

I could always get decent recording through Alsa,
but now I can get good 16000 recordings through AudioRecord.
I need to beat on it to accept other rates besides 8000 & 16000.

Skype is still getting buffer overruns and the mute switch does not work.
Still, it looks like it manages to record a fraction of a second correctly.


asound.conf above has been edited 2002-05-02, ctl's don't take device #
 
Last edited:
  • Like
Reactions: mrWax

Renate

Recognized Contributor / Inactive Recognized Dev
So I was chatting with this Chinese lady.
She was very patient even though I kept calling her and my Chinese is poor at best.
Of course she is the nice lady on the Skype loopback test.
(The Chinese one seems to work more reliably than the English one.)

What I mean to say is that Skype works fine.

The problem is that the Nook reports a ridiculously small minimum buffer size for audio.
If you hack /system/framework.jar it will use a realistically sized buffer.
The enclosed text file replaces the corresponding method in the smali for AudioRecord.

Code:
adb pull /system/framework/framework.jar
apktool d framework.jar Framework
Then you edit in the replacement in smali/android/media/AudioRecord.smali
Code:
apktool b Framework framework.jar
adb push framework.jar /system/framework/

Note: Changing this will make my tool AudioCtl say that it supports every sampling rate.
This is not true, it remains at just 8000 & 16000 mono.
I'm still working on beating on the init to do quality recording at 44.1
 

Attachments

  • parte.txt
    580 bytes · Views: 44
Last edited:
  • Like
Reactions: mrWax

Renate

Recognized Contributor / Inactive Recognized Dev
Yet more mods, sigh.

This one prevents rotating of your arrow keys when in landscape mode.
Any arrow keys are on an external keyboard which doesn't rotate.

Code:
adb pull /system/framework/services.jar
apktool d services.jar Services

Then you edit in the replacement in smali/com/android/server/KeyInputQueue.smali
Code:

Code:
apktool b Services services.jar
adb push services.jar /system/services/
 

Attachments

  • partf.txt
    440 bytes · Views: 74
Last edited:
  • Like
Reactions: Kwiz Hade and mrWax

Renate

Recognized Contributor / Inactive Recognized Dev
Ok, just a bit of a heads up and a bump.
I've beaten on the code and I've got high quality recording at 44.1 to work.
The fix is binary editing libaudio.so to allow more rates/formats.
I'm working on making something cleaner, but it is proof of concept.

Eventually I'd like to get Lame MP3 encoder working with it,
but for now big micro SD cards are cheap enough.

If you're really desperate to try this out, use a 1.1.2 libaudio.so
Code:
[00009188] B1 F5 FA 54 => 70 BD 00 BF
[000091EC] 6C 33 => 00 05

Note: libaudio.so is the Android layer interface to ALSA.
If you are using the audio recorder application further down,
it uses ALSA directly and bypasses this file.
 
Last edited:
  • Like
Reactions: mrWax

mrWax

Senior Member
Jan 31, 2012
147
24
i am now trying to install adb on linux (i am new immigrant to the ubuntu) in a time i hope i'll finaly test you mods. especially skype and casablanca on NST :]
 

Renate

Recognized Contributor / Inactive Recognized Dev
As usual, a heads-up, a bit of a bump and seeing whether there is interest.

Android does not support 24 bit recording.
Yes, you can hack stuff to configure the ALSA to work correctly,
but the Android buffer handling didn't plan for 24 bits and munches the alignment.

I've got an application now that will do 24 bit recording without using the Android audio.
I haven't actually gotten it to the point where you can play it back (on the Nook). :eek:
However, with a Lexicon Alpha interface and a Shure SM58 it makes a handy field recorder.

No, I'm not an audio purist, but it's very handy to record with lots of bits in case you have to raise the gain when mixing it later.
For final recordings, 16 bit is fine with me.
 
  • Like
Reactions: mrWax

mrWax

Senior Member
Jan 31, 2012
147
24
pack

Cloud you please make automated pack or tutorial how to incorporate all the mods you've developed?
 

Renate

Recognized Contributor / Inactive Recognized Dev
Cloud you please make automated pack or tutorial how to incorporate all the mods you've developed?

Mmm, you do have a valid point.
These audio mods are getting a bit out of hand.
You need a score card just to keep track of them.

I'm trying to find some cleaner ways to do some of these mods.
Right now, this is for intrepid folks that want to dive back into the thread.
I'm working on custom permissions for audio hardware access.
I will be doing a recap shortly.

Still, I'd like to get some feedback on what people want this for.

  • MP3 playing
  • Internet radio
  • Skype
  • Home recording
  • Memo taking
  • Speech to text
 

Top Liked Posts

  • There are no posts matching your filters.
  • 18
    Hello!

    I have been asked into looking for usb host support for nook touch. The hardware appears to be pretty similar to Nook Color, so there were no troubles in that area.


    The kernel used by B&N for the Nook Touch is somewhat older than .32 kernel used for Nook Color, so the patch itself required some massage. Surprisingly B&N kernel already has usb host support compiled in, so you don't even need to change anything in kernel config, just apply the patch.

    Just like in Nook Color, the id pin in the usb receptacle is not connected anywhere, so a special app is needed to switch the host mode on and off. The Nook Color usbhost switcher should work: https://github.com/verygreen/Nook-Color-usbhost-switcher though I cannot compile it for eclair, so I guess that needs some more massage and help here would be appreciated.

    Meanwhile you can simply switch the mode from adb, type
    Code:
    echo host > /sys/devices/platform/musb_hdrc/mode
    to enable usb host mode and type
    Code:
    echo peripheral > /sys/devices/platform/musb_hdrc/mode
    to disable it.
    The LED at the bottom that usually indicates charging status will light up in usb host mode even if the power is not connected.

    The upside is you don't need a special OTG cable and can just use gender changer on your existing nook cable if you so desire.

    Now, problems ;)
    • I have not tracked why yet, but self powered mode only works when you try to enable it first with external power plugged in first.
    • The user-friendly tool for usbhost mode switching needs to be compiled for eclair
    • The self-powered mode is very faint. Keeps up with my keyboard, but not even with a simple usb hub.
    • Battery drain is significant, though not sure what part of it is attributed to the usbhost mode and what to adb over wifi
    • Eclair init is buggy so input devices are unusable without a patch, see commit 6405c6953fa02d41d9f6377f4cdb947604f481c4 in google tree to sytem/core/init. I am attaching recompiled init binary that works.

    Attachments: binary.zip contains:
    • uImage - prebuilt 1.1 kernel with the patch
    • uRamdisk - root ramdisk with fixed init, adb over wifi
    • init - just recompiled init binary for those who might need it
    usbhost_patch.zip - just the patch itself in it's current form.

    THANKS TO:
    andrewed, who asked me to do this and also provided me with a device. He is on a quest to touchtype on e-paper with a USB physical keyboard, all described here: Project: E-Paper Tablet (typable!)
    7
    This is chinese for me again, sorry...

    Ni hao ma?

    Ok, no problem.

    Here is the official (interim, hacked) way to get your Nook to be an MP3 player.

    1. Root
    2. Install mali100's uImage with USB host mode and audio drivers
    3. Install superuser.apk and su
    4. Install UsbMode-1.4.apk (see below)
    5. Install AudioCtl-1.0.apk (see below)
    6. Create the text file /system/etc/asound.conf as shown here
    7. Plug in USB audio adapter through a special OTG cable adapter
    8. Using UsbMode, set in host mode
    9. Run AudioCtl, it should make beeping noises
    10. Go to your file manager and select a suitable song to play
    11. Goto step #10

    AudioCtl is very much a version 1.0
    It is necessary to use now as a workaround due to problems with mediaserver.
    You only need to run it once after each time of turning on the USB audio adapter.
    In the future, AudioCtl will have useful features.

    Note: Ignore all that stuff about ps, kill, mediaserver, etc. AudioCtl obviates all that.
    5
    USB Host Mode Swicth for Nook Simple Touch

    Attached is a Nook Simple Touch version of verygreens USB Host Mode switching app.

    Requires properly installed "su" in /system/bin

    Let me know if there are problems.
    5
    Ok, here's a summary.
    Depending on what you want to do not all of this may be required.

    For basic playback
    For basic recording or Skype
    • Modify /system/lib/hw/libaudio.so
      Code:
      [00009188] B1 F5 FA 54 => 70 BD 00 BF
      [000091EC] 6C 33 => 00 05
    • Patch /system/framework/framework.jar with AudioRecord.smali using mergesmali, in signature, in Nook121patch
    For recording directly through ALSA
    • Recorder.apk, in signature
    • Modify /system/etc/permissions
      Code:
         <permission name="android.permission.WRITE_EXTERNAL_STORAGE" >
             <group gid="sdcard_rw" />
             [b]<group gid="audio" />[/b]
         </permission>
    Jeez, it seems like a lot.
    4
    Is it possible to change the keyboard layout?

    Of course.

    There are two levels of processing turning a key press into a character.
    The first is mapping of the scan code into a key code.
    The second is mapping the key code and meta keys (shift, alt, etc) into a character.

    The first mapping is done using files like /system/usr/keylayout/qwerty.kl
    The second mapping is done using files like /system/usr/keychars/qwerty.kcm.bin
    The first file is conveniently in plain text, the second is a simple binary file.

    If you are simply swapping keys around you only need to change the .kl file
    If you want to make it so that shift 4 is Euro instead of dollar you need to change the kcm.bin file.

    You can just edit the .kl file. Before:
    Code:
      key  21  Y
    After:
    Code:
      key  21  Z
    This would make the key layout more "German-like" by making the center key in the top alpha row be considered the 'Z' key.

    The .kcm.bin are compiled files from source.
    I haven't looked into where the compiler comes from, I just modify the stock kcm.bin by hand.

    The file is broken down into 16 byte chunks with a 16 byte header.
    Here is the chunk for C (on my modified version):
    Code:
    000100 1F 00 00 00 43 00 32 00 63 00 43 00 E7 00 C7 00
    This means:
    • This chunk is about KEYCODE_C (0x1f) (uses Android key codes)
    • The visual for this key is 'C' (0x0043)
    • On a numeric keypad this would dial a 2 (0x0032) as in ABC on a phone
    • The unshifted UTF-16 value is 'c' (0x0063)
    • The shifted UTF-16 value is 'C' (0x0043)
    • The alt modified UTF-16 value 'ç' (0x00e7)
    • The alt-shift modified UTF-16 value is 'Ç' (0x00c7)

    You can also use alt combos for combining diacritics:
    • 0x0300 grave accent
    • 0x0301 acute accent
    • 0x0302 circumflex accent
    • 0x0303 tilde accent
    • 0x0308 umlaut accent

    To replace these files on your Nook, you will need to remount your system as R/W:
    Code:
    mount -o rw,remount /dev/block/mmcblk0p5 /system

    You can get fancier if you want to have some USB keyboards US and some Belgian.

    I await my shipment of Belgian chocolates. :D